Skip to main content
The TypeScript compiler represents source code as an Abstract Syntax Tree (AST) composed of nodes. All nodes implement the base Node interface and are classified by their SyntaxKind.

Base Node Interface

All AST nodes extend the Node interface:

Key Properties

PropertyTypeDescription
kindSyntaxKindThe syntax kind identifying the node type
flagsNodeFlagsBitwise flags for node properties
parentNodeParent node in the AST
posnumberStart position in source text
endnumberEnd position in source text

Core Node Types

Declaration Nodes

Declaration nodes represent entities that introduce symbols into scope:
  • VariableDeclaration - Variable declarations
  • FunctionDeclaration - Function declarations
  • ClassDeclaration - Class declarations
  • InterfaceDeclaration - Interface declarations
  • TypeAliasDeclaration - Type alias declarations
  • EnumDeclaration - Enum declarations
  • ParameterDeclaration - Parameter declarations

Expression Nodes

Expressions are nodes that can be evaluated to produce a value:
Common expression types:
TypeDescription
IdentifierVariable or property name
BinaryExpressionBinary operations (e.g., a + b)
CallExpressionFunction calls
PropertyAccessExpressionProperty access (e.g., obj.prop)
ElementAccessExpressionBracket notation (e.g., arr[0])
ArrowFunctionArrow function expressions
FunctionExpressionFunction expressions

Statement Nodes

Statements are executable units of code:

Type Nodes

Type nodes represent TypeScript type annotations:

Container Nodes

Some nodes act as containers for other declarations:

LocalsContainer

Nodes that can contain local symbols:
  • SourceFile
  • FunctionDeclaration
  • ModuleDeclaration
  • Block
  • ForStatement
  • CatchClause

FlowContainer

Nodes with control flow analysis:
  • Functions and methods
  • Statements (if, while, for, etc.)
  • Expressions with side effects

Common Node Patterns

Signature Declarations

Used by:
  • FunctionDeclaration
  • MethodDeclaration
  • ConstructorDeclaration
  • CallSignatureDeclaration
  • ConstructSignatureDeclaration

Variable Declarations

Parameter Declarations

Working with Nodes

Type Guards

Use type guards to narrow node types:

Traversing the AST

Node Relationships

Parent-Child

Every node (except the root) has a parent:

Source File

Get the source file for any node:

See Also