Skip to main content
Module

x/ts_morph/mod.ts>Type

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Very Popular
Go to Latest
class Type
import { Type } from "https://deno.land/x/ts_morph@15.1.0/mod.ts";

Constructors

new
protected
Type()

Type Parameters

optional
TType extends ts.Type = ts.Type

Properties

readonly
compilerType: TType

Gets the underlying compiler type.

Methods

getAliasSymbol(): Symbol | undefined

Gets the alias symbol if it exists.

Gets the alias symbol if it exists, or throws.

Gets the alias type arguments.

Gets the apparent properties of the type.

getApparentProperty(name: string): Symbol | undefined

Gets an apparent property.

getApparentProperty(findFunction: (declaration: Symbol) => boolean): Symbol | undefined

Gets the apparent type.

getArrayElementType(): Type<ts.Type> | undefined

Gets the array element type or returns undefined if it doesn't exist (ex. for T[] it would be T).

Gets the array element type or throws if it doesn't exist (ex. for T[] it would be T).

Gets the base type of a literal type.

For example, for a number literal type it will return the number type.

getBaseTypes(): Type<ts.BaseType>[]

Gets the base types.

Gets the call signatures.

getConstraint(): Type<ts.Type> | undefined

Gets the constraint or returns undefined if it doesn't exist.

Gets the constraint or throws if it doesn't exist.

Gets the construct signatures.

getDefault(): Type<ts.Type> | undefined

Gets the default type or returns undefined if it doesn't exist.

Gets the default type or throws if it doesn't exist.

Gets the type flags.

Gets the intersection types (ex. for T & U it returns the array [T, U]).

getLiteralFreshType(): Type<ts.LiteralType> | undefined

Gets the fresh type of the literal or returns undefined if this is not a literal type.

Note: I have no idea what this means. Please help contribute to these js docs if you know.

getLiteralFreshTypeOrThrow(): Type<ts.LiteralType>

Gets the fresh type of the literal or throws if this is not a literal type.

Note: I have no idea what this means. Please help contribute to these js docs if you know.

getLiteralRegularType(): Type<ts.LiteralType> | undefined

Gets the regular type of the literal or returns undefined if this is not a literal type.

Note: I have no idea what this means. Please help contribute to these js docs if you know.

Gets the regular type of the literal or throws if this is not a literal type.

Note: I have no idea what this means. Please help contribute to these js docs if you know.

getLiteralValue():
| string
| number
| ts.PseudoBigInt
| undefined

Gets the value of a literal or returns undefined if this is not a literal type.

getLiteralValueOrThrow(): string | number | ts.PseudoBigInt

Gets the value of the literal or throws if this is not a literal type.

Gets the non-nullable type.

getNumberIndexType(): Type | undefined

Gets the number index type.

Gets the object flags.

Gets the properties of the type.

getProperty(name: string): Symbol | undefined

Gets a property or returns undefined if it does not exist.

getProperty(findFunction: (declaration: Symbol) => boolean): Symbol | undefined

Gets a property or returns undefined if it does not exist.

getPropertyOrThrow(name: string): Symbol

Gets a property or throws if it doesn't exist.

getPropertyOrThrow(findFunction: (declaration: Symbol) => boolean): Symbol

Gets a property or throws if it doesn't exist.

getStringIndexType(): Type | undefined

Gets the string index type.

getSymbol(): Symbol | undefined

Gets the symbol of the type.

Gets the symbol of the type or throws.

getTargetType(): Type<ts.GenericType> | undefined

Returns the generic type when the type is a type reference, returns itself when it's already a generic type, or otherwise returns undefined.

For example:

  • Given type reference Promise<string> returns Promise<T>.
  • Given generic type Promise<T> returns the same Promise<T>.
  • Given string returns undefined.
getTargetTypeOrThrow(): Type<ts.GenericType>

Returns the generic type when the type is a type reference, returns itself when it's already a generic type, or otherwise throws an error.

For example:

  • Given type reference Promise<string> returns Promise<T>.
  • Given generic type Promise<T> returns the same Promise<T>.
  • Given string throws an error.
getText(enclosingNode?: Node, typeFormatFlags?: TypeFormatFlags): string

Gets the type text.

Gets the individual element types of the tuple.

Gets type arguments.

Gets the union types (ex. for T | U it returns the array [T, U]).

isAnonymous(): boolean

Gets if this is an anonymous type.

isAny(): boolean

Gets if this is an any type.

isArray(): boolean

Gets if this is an array type.

isBoolean(): boolean

Gets if this is a boolean type.

isBooleanLiteral(): boolean

Gets if this is a boolean literal type.

isClass(): boolean

Gets if this is a class type.

Gets if this is a class or interface type.

isEnum(): boolean

Gets if this is an enum type.

isEnumLiteral(): boolean

Gets if this is an enum literal type.

isInterface(): boolean

Gets if this is an interface type.

isIntersection(): boolean

Gets if this is an intersection type.

isLiteral(): boolean

Gets if this is a literal type.

isNull(): boolean

Gets if this is the null type.

isNullable(): boolean

Gets if the type is possibly null or undefined.

isNumber(): boolean

Gets if this is a number type.

isNumberLiteral(): boolean

Gets if this is a number literal type.

isObject(): boolean

Gets if this is an object type.

isString(): boolean

Gets if this is a string type.

isStringLiteral(): boolean

Gets if this is a string literal type.

Gets if this is a template literal type.

isTuple(): boolean

Gets if this is a tuple type.

Gets if this is a type parameter.

isUndefined(): boolean

Gets if this is the undefined type.

isUnion(): boolean

Gets if this is a union type.

Gets if this is a union or intersection type.

isUnknown(): boolean

Gets if this is the unknown type.