Overview
TheTypeChecker is the semantic analysis engine of the TypeScript Compiler API. It provides methods to query type information, resolve symbols, and perform type-related operations on the Abstract Syntax Tree (AST).
Getting a TypeChecker
The TypeChecker is obtained from a Program instance:Symbol Methods
getSymbolAtLocation()
Returns the symbol for a node at a specific location.Node
required
The AST node to get the symbol for
Symbol | undefined
The symbol at the location, or undefined if not found
getTypeOfSymbolAtLocation()
Returns the type of a symbol at a specific location.Symbol
required
The symbol to get the type for
Node
required
The location node
Type
The type of the symbol at that location
getTypeOfSymbol()
Returns the type of a symbol.Symbol
required
The symbol to get the type for
Type
The type of the symbol
getDeclaredTypeOfSymbol()
Returns the declared type of a symbol (for classes, interfaces, etc.).Symbol
required
The symbol to get the declared type for
Type
The declared type of the symbol
getFullyQualifiedName()
Returns the fully qualified name of a symbol.Symbol
required
The symbol to get the name for
string
The fully qualified name
Type Methods
getTypeAtLocation()
Returns the type of an expression at a specific location.Node
required
The node to get the type for
Type
The type at the location
getTypeFromTypeNode()
Converts a type node to a Type object.TypeNode
required
The type node to convert
Type
The Type object
getPropertiesOfType()
Returns all properties of a type.Type
required
The type to get properties for
Symbol[]
Array of property symbols
getPropertyOfType()
Returns a specific property of a type by name.Type
required
The type to search
string
required
The name of the property
Symbol | undefined
The property symbol, or undefined if not found
getSignaturesOfType()
Returns all signatures of a type (for functions, constructors, etc.).Type
required
The type to get signatures for
SignatureKind
required
The kind of signature (Call, Construct, etc.)
readonly Signature[]
Array of signatures
getReturnTypeOfSignature()
Returns the return type of a signature.Signature
required
The signature to get the return type for
Type
The return type
getBaseTypes()
Returns the base types of a class or interface.InterfaceType
required
The interface or class type
BaseType[]
Array of base types
getTypeArguments()
Returns the type arguments for a type reference.TypeReference
required
The type reference
readonly Type[]
Array of type arguments
Type Conversion Methods
typeToString()
Converts a type to a string representation.Type
required
The type to convert
Node
Optional enclosing declaration for context
TypeFormatFlags
Optional formatting flags
string
String representation of the type
symbolToString()
Converts a symbol to a string representation.Symbol
required
The symbol to convert
Node
Optional enclosing declaration
SymbolFlags
Optional meaning flags
SymbolFormatFlags
Optional formatting flags
string
String representation of the symbol
signatureToString()
Converts a signature to a string representation.Signature
required
The signature to convert
Node
Optional enclosing declaration
TypeFormatFlags
Optional formatting flags
SignatureKind
Optional signature kind
string
String representation of the signature
typeToTypeNode()
Converts a Type to a TypeNode AST node.Type
required
The type to convert
Node | undefined
required
Enclosing declaration for context
NodeBuilderFlags | undefined
required
Node builder flags
TypeNode | undefined
The TypeNode AST node
Utility Methods
getNullableType()
Returns a nullable version of a type.Type
required
The type to make nullable
TypeFlags
required
Flags indicating which nullable types to add (null, undefined)
Type
The nullable type
getNonNullableType()
Removes null and undefined from a type.Type
required
The type to make non-nullable
Type
The non-nullable type
getWidenedType()
Returns a widened version of a type.Type
required
The type to widen
Type
The widened type
getAliasedSymbol()
Follows all aliases to get the original symbol.Symbol
required
The symbol to resolve
Symbol
The original aliased symbol
getExportSymbolOfSymbol()
Returns the exported symbol for a local symbol.Symbol
required
The local symbol
Symbol
The exported symbol