Skip to main content

Overview

The TypeChecker 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
Node
required
The AST node to get the symbol for
return
Symbol | undefined
The symbol at the location, or undefined if not found

getTypeOfSymbolAtLocation()

Returns the type of a symbol at a specific location.
symbol
Symbol
required
The symbol to get the type for
node
Node
required
The location node
return
Type
The type of the symbol at that location

getTypeOfSymbol()

Returns the type of a symbol.
symbol
Symbol
required
The symbol to get the type for
return
Type
The type of the symbol

getDeclaredTypeOfSymbol()

Returns the declared type of a symbol (for classes, interfaces, etc.).
symbol
Symbol
required
The symbol to get the declared type for
return
Type
The declared type of the symbol

getFullyQualifiedName()

Returns the fully qualified name of a symbol.
symbol
Symbol
required
The symbol to get the name for
return
string
The fully qualified name

Type Methods

getTypeAtLocation()

Returns the type of an expression at a specific location.
node
Node
required
The node to get the type for
return
Type
The type at the location

getTypeFromTypeNode()

Converts a type node to a Type object.
node
TypeNode
required
The type node to convert
return
Type
The Type object

getPropertiesOfType()

Returns all properties of a type.
type
Type
required
The type to get properties for
return
Symbol[]
Array of property symbols

getPropertyOfType()

Returns a specific property of a type by name.
type
Type
required
The type to search
propertyName
string
required
The name of the property
return
Symbol | undefined
The property symbol, or undefined if not found

getSignaturesOfType()

Returns all signatures of a type (for functions, constructors, etc.).
type
Type
required
The type to get signatures for
kind
SignatureKind
required
The kind of signature (Call, Construct, etc.)
return
readonly Signature[]
Array of signatures

getReturnTypeOfSignature()

Returns the return type of a signature.
signature
Signature
required
The signature to get the return type for
return
Type
The return type

getBaseTypes()

Returns the base types of a class or interface.
type
InterfaceType
required
The interface or class type
return
BaseType[]
Array of base types

getTypeArguments()

Returns the type arguments for a type reference.
type
TypeReference
required
The type reference
return
readonly Type[]
Array of type arguments

Type Conversion Methods

typeToString()

Converts a type to a string representation.
type
Type
required
The type to convert
enclosingDeclaration
Node
Optional enclosing declaration for context
flags
TypeFormatFlags
Optional formatting flags
return
string
String representation of the type

symbolToString()

Converts a symbol to a string representation.
symbol
Symbol
required
The symbol to convert
enclosingDeclaration
Node
Optional enclosing declaration
meaning
SymbolFlags
Optional meaning flags
flags
SymbolFormatFlags
Optional formatting flags
return
string
String representation of the symbol

signatureToString()

Converts a signature to a string representation.
signature
Signature
required
The signature to convert
enclosingDeclaration
Node
Optional enclosing declaration
flags
TypeFormatFlags
Optional formatting flags
kind
SignatureKind
Optional signature kind
return
string
String representation of the signature

typeToTypeNode()

Converts a Type to a TypeNode AST node.
type
Type
required
The type to convert
enclosingDeclaration
Node | undefined
required
Enclosing declaration for context
flags
NodeBuilderFlags | undefined
required
Node builder flags
return
TypeNode | undefined
The TypeNode AST node

Utility Methods

getNullableType()

Returns a nullable version of a type.
type
Type
required
The type to make nullable
flags
TypeFlags
required
Flags indicating which nullable types to add (null, undefined)
return
Type
The nullable type

getNonNullableType()

Removes null and undefined from a type.
type
Type
required
The type to make non-nullable
return
Type
The non-nullable type

getWidenedType()

Returns a widened version of a type.
type
Type
required
The type to widen
return
Type
The widened type

getAliasedSymbol()

Follows all aliases to get the original symbol.
symbol
Symbol
required
The symbol to resolve
return
Symbol
The original aliased symbol

getExportSymbolOfSymbol()

Returns the exported symbol for a local symbol.
symbol
Symbol
required
The local symbol
return
Symbol
The exported symbol

Primitive Type Getters

Complete Example

See Also