import ts from 'typescript'; export interface InterfaceExtend { name: string; types?: ts.TypeNode[]; } export declare const Type: { /** * "any" type * ```typescript * Node.Const({ type: Type.Any, name: 'a', }) * // Would generate * const a: any; * ``` */ Any: ts.KeywordTypeNode; /** * "string" type * ```typescript * Node.Const({ type: Type.String, name: 'a', }) * // Would generate * const a: string; * ``` */ String: ts.KeywordTypeNode; /** * "number" type * ```typescript * Node.Const({ type: Type.Number, name: 'a', }) * // Would generate * const a: number; * ``` */ Number: ts.KeywordTypeNode; /** * "null" type * ```typescript * Node.Const({ type: Type.Union([Type.Number, Type.Null]), name: 'a' }) * // Would generate * const a: number | null; * ``` */ Null: ts.LiteralTypeNode; /** * "boolean" type * ```typescript * Node.Const({ type: Type.Boolean, name: 'a', }) * // Would generate * const a: boolean; * ``` */ Boolean: ts.KeywordTypeNode; /** * "object" type * ```typescript * Node.Const({ type: Type.Object, name: 'a', }) * // Would generate * const a: object; * ``` */ Object: ts.KeywordTypeNode; /** * "void" type * ```typescript * Node.Const({ type: Type.Union([Type.Number, Type.Void]), name: 'a' }) * // Would generate * const a: number | void; * ``` */ Void: ts.KeywordTypeNode; /** * "unknown" type * ```typescript * Node.Const({ type: Type.Unknown, name: 'a' }) * // Would generate * const a: unknown; * ``` */ Unknown: ts.KeywordTypeNode; /** * "never" type * ```typescript * Node.Const({ type: Type.Union([Type.Number, Type.Never]), name: 'a' }) * // Would generate * const a: number | never; * ``` */ Never: ts.KeywordTypeNode; /** * "undefined" type * ```typescript * Node.Const({ type: Type.Union([Type.Number, Type.Undefined]), name: 'a' }) * // Would generate * const a: number | undefined; * ``` */ Undefined: ts.KeywordTypeNode; /** * Type literal * ```typescript * Node.Const({ * name: 'a', * type: Type.TypeLiteral({ * props: [ * Type.Prop({ name: 'test1', type: Type.String, isOptional: true }), * Type.Prop({ name: 'test2', type: Type.Number }), * ], * }), * }) * // Would generate * const a: { * test1?: string; * test2: number; * }; * ``` */ TypeLiteral: ({ props, index, }?: { props?: ts.TypeElement[] | undefined; index?: ts.IndexSignatureDeclaration | undefined; }) => ts.TypeLiteralNode; /** * Array type, can be nested * ```typescript * Node.Const({ type: Type.Array(Type.String), name: 'a' }) * // Would generate * const a: string[]; * ``` * ```typescript * Node.Const({ type: Type.Array(Type.Array(Type.String)), name: 'a' }) * // Would generate * const a: string[][]; * ``` */ Array: (type: ts.TypeNode) => ts.ArrayTypeNode; /** * union type * ```typescript * Node.Const({ type: Type.Union([Type.String, Type.Number]), name: 'a' }) * // Would generate * const a: string | number; * ``` */ Union: (types: ts.TypeNode[]) => ts.UnionTypeNode; /** * intersection type * ```typescript * Node.Const({ * type: Type.Intersection([ * Type.TypeLiteral({ props: [Type.Prop({ name: 'b', type: Type.String })] }), * Type.TypeLiteral({ props: [Type.Prop({ name: 'c', type: Type.String })] }), * ]), * name: 'a', * }) * // Would generate * const a: { b: string } & { c: string }; * ``` */ Intersection: (types: ts.TypeNode[]) => ts.IntersectionTypeNode; /** * A type of a literal value * ```typescript * Node.Const({ type: Type.Union([Type.Literal(1), Type.Literal(2)]), name: 'a' }) * // Would generate * const a: 1 | 2; * ``` */ Literal: (value: unknown) => ts.LiteralTypeNode | ts.KeywordTypeNode; /** * A literal string type. * Useful in situations where you need a ts.StringLiteral specifically * ```typescript * Node.Const({ type: Type.Union([Type.LiteralString("one"), Type.LiteralString("two")]), name: 'a' }) * // Would generate * const a: "one" | "two"; * ``` */ LiteralString: (value: string) => ts.StringLiteral; /** * Arrow function type * ```typescript * Type.Arrow({ args: [Type.Param({ name: 'a', type: Type.String })], ret: Type.Number }) * // Would generate * (a: string) => number * ``` */ Arrow: ({ args, ret }: { args: ts.ParameterDeclaration[]; ret: ts.TypeNode; }) => ts.FunctionTypeNode; /** * Set something as optional - used internally throughout the types */ Optional: (isOptional?: boolean) => ts.Token | undefined; /** * Set something as public - used internally throughout the types */ Public: (isPublic?: boolean) => ts.Token[]; /** * Set something as readonly - used internally throughout the types */ Readonly: (isReadonly?: boolean) => ts.Token[]; /** * Set something as private - used internally throughout the types */ Private: (isPrivate?: boolean) => ts.Token[]; /** * Set something as exported - used internally throughout the types */ Export: (isExport?: boolean, isDefault?: boolean) => ts.Token[]; /** * Set something as protected - used internally throughout the types */ Protected: (isProtected?: boolean) => ts.Token[]; /** * Define a method type * * ```typescript * Type.Interface({ * name: 'test', * props: [ * Type.Method({ * name: 'get', * params: [Type.Param({ name: 'T1', type: Type.Number })], * }), * Type.Method({ * name: 'get', * typeArgs: [Type.TypeArg({ name: 'T2' })], * params: [Type.Param({ name: 'T3', type: Type.String, isOptional: true })], * type: Type.Any, * }), * ], * }) * // Would generate * interface test { * get(T1: number); * get(T3?: string): any; * } * ``` */ Method: ({ typeArgs, name, params, type, jsDoc, isOptional, }: { typeArgs?: ts.TypeParameterDeclaration[] | undefined; params: ts.ParameterDeclaration[]; name: string | ts.Identifier; isOptional?: boolean | undefined; type?: ts.TypeNode | undefined; jsDoc?: string | undefined; }) => ts.MethodSignature; /** * Define a property type for an interface / type literal * * ```typescript * Type.Interface({ name: 'test', props: [Type.Prop({ name: '11231', type: Type.String })] }) * // Would generate * interface test { * "11231": string; * } * ``` */ Prop: ({ name, type, isReadonly, isOptional, isPublic, isPrivate, isProtected, jsDoc, }: { name: ts.PropertyName | string | ts.Identifier; type: ts.TypeNode; isOptional?: boolean | undefined; isReadonly?: boolean | undefined; isPublic?: boolean | undefined; isPrivate?: boolean | undefined; isProtected?: boolean | undefined; jsDoc?: string | undefined; }) => ts.PropertySignature; /** * Define a parameter function types, arrow function types and method types * * ```typescript * Type.Arrow({ args: [Type.Param({ name: 'a', type: Type.String })], ret: Type.Number }) * // Would generate * (a: string) => number * ``` */ Param: ({ name, type, isOptional, isReadonly, }: { name: string | ts.Identifier; type?: ts.TypeNode | undefined; isOptional?: boolean | undefined; isReadonly?: boolean | undefined; }) => ts.ParameterDeclaration; /** * Type arg for interfaces and type aliases * * ```typescript * Type.Interface({ name: 'Test', typeArgs: [Type.TypeArg({ name: 'Best' })] }) * // Would generate * interface Test { * } * ``` */ TypeArg: ({ name, ext, defaultType, isReadonly, isPublic, isPrivate, isProtected, }: { name: string | ts.Identifier; ext?: ts.TypeNode | undefined; defaultType?: ts.TypeNode | undefined; isReadonly?: boolean | undefined; isPublic?: boolean | undefined; isPrivate?: boolean | undefined; isProtected?: boolean | undefined; }) => ts.TypeParameterDeclaration; /** * Index signature for alias * ```typescript * Type.Interface({ * name: 'Test', * index: Type.Index({ name: 'index', nameType: Type.Number, type: Type.Any }), * }) * // Would generate * interface Test { * [index: number]: any; * } * ``` */ Index: ({ name, nameType, type, isReadonly, }: { name: string | ts.Identifier; nameType: ts.TypeNode; type: ts.TypeNode; isReadonly?: boolean | undefined; }) => ts.IndexSignatureDeclaration; /** * References a type alias * ```typescript * Type.Referance('MyType', [Type.String]) * // Would generate * MyType * ``` */ Referance: (name: string | ts.Identifier | string[], types?: ts.TypeNode[]) => ts.TypeReferenceNode; /** * Tuple type * ```typescript * Type.Tuple([Type.String, Type.Number]) * // Would generate * [ * string, * number, * ] * ``` */ Tuple: (types: ts.TypeNode[]) => ts.TupleTypeNode; /** * Raw type expression * ```typescript * Type.TypeExpression({ name: 'T' }) * // Would generate * T * ``` */ TypeExpression: ({ name, types, }: { name: string | ts.Identifier; types?: ts.TypeNode[] | undefined; }) => ts.ExpressionWithTypeArguments; /** * Type alias * ```typescript * Type.Alias({ name: 'mytype', type: Type.String }) * // Would generate * type mytype = string; * ``` */ Alias: ({ name, type, typeArgs, isExport, isDefault, jsDoc, }: { name: string | ts.Identifier; type: ts.TypeNode; isExport?: boolean | undefined; isDefault?: boolean | undefined; typeArgs?: ts.TypeParameterDeclaration[] | undefined; jsDoc?: string | undefined; }) => ts.TypeAliasDeclaration; /** * Define a method type * * ```typescript * Type.Interface({ * name: 'test', * props: [Type.Prop({ name: 'val', type: Type.Number })], * }) * // Would generate * interface test { * val: number; * } * ``` */ Interface: ({ name, props, index, typeArgs, ext, isExport, isDefault, jsDoc, }: { name: string | ts.Identifier; props?: ts.TypeElement[] | undefined; index?: ts.IndexSignatureDeclaration | undefined; typeArgs?: ts.TypeParameterDeclaration[] | undefined; ext?: InterfaceExtend[] | undefined; isExport?: boolean | undefined; isDefault?: boolean | undefined; jsDoc?: string | undefined; }) => ts.InterfaceDeclaration; };