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.The AST node to get the symbol for
The symbol at the location, or undefined if not found
getTypeOfSymbolAtLocation()
Returns the type of a symbol at a specific location.The symbol to get the type for
The location node
The type of the symbol at that location
getTypeOfSymbol()
Returns the type of a symbol.The symbol to get the type for
The type of the symbol
getDeclaredTypeOfSymbol()
Returns the declared type of a symbol (for classes, interfaces, etc.).The symbol to get the declared type for
The declared type of the symbol
getFullyQualifiedName()
Returns the fully qualified name of a symbol.The symbol to get the name for
The fully qualified name
Type Methods
getTypeAtLocation()
Returns the type of an expression at a specific location.The node to get the type for
The type at the location
getTypeFromTypeNode()
Converts a type node to a Type object.The type node to convert
The Type object
getPropertiesOfType()
Returns all properties of a type.The type to get properties for
Array of property symbols
getPropertyOfType()
Returns a specific property of a type by name.The type to search
The name of the property
The property symbol, or undefined if not found
getSignaturesOfType()
Returns all signatures of a type (for functions, constructors, etc.).The type to get signatures for
The kind of signature (Call, Construct, etc.)
Array of signatures
getReturnTypeOfSignature()
Returns the return type of a signature.The signature to get the return type for
The return type
getBaseTypes()
Returns the base types of a class or interface.The interface or class type
Array of base types
getTypeArguments()
Returns the type arguments for a type reference.The type reference
Array of type arguments
Type Conversion Methods
typeToString()
Converts a type to a string representation.The type to convert
Optional enclosing declaration for context
Optional formatting flags
String representation of the type
symbolToString()
Converts a symbol to a string representation.The symbol to convert
Optional enclosing declaration
Optional meaning flags
Optional formatting flags
String representation of the symbol
signatureToString()
Converts a signature to a string representation.The signature to convert
Optional enclosing declaration
Optional formatting flags
Optional signature kind
String representation of the signature
typeToTypeNode()
Converts a Type to a TypeNode AST node.The type to convert
Enclosing declaration for context
Node builder flags
The TypeNode AST node
Utility Methods
getNullableType()
Returns a nullable version of a type.The type to make nullable
Flags indicating which nullable types to add (null, undefined)
The nullable type
getNonNullableType()
Removes null and undefined from a type.The type to make non-nullable
The non-nullable type
getWidenedType()
Returns a widened version of a type.The type to widen
The widened type
getAliasedSymbol()
Follows all aliases to get the original symbol.The symbol to resolve
The original aliased symbol
getExportSymbolOfSymbol()
Returns the exported symbol for a local symbol.The local symbol
The exported symbol