Type definitions for the TypeScript-ESTree AST specification, including parser options and AST node types
—
Complete type definitions for all AST node structures with parent relationship augmentations, providing strongly-typed access to the entire TypeScript and JavaScript syntax tree.
The complete TypeScript ESTree namespace containing all AST node type definitions.
declare namespace TSESTree {
// Core data interface (from ast-spec)
interface NodeOrTokenData {
type: string;
loc: SourceLocation;
range: Range;
}
// Base node interface with parent relationship
interface BaseNode extends NodeOrTokenData {
type: AST_NODE_TYPES;
parent: Node; // Added by @typescript-eslint/types package
}
// Program node (root of AST)
interface Program extends NodeOrTokenData {
type: AST_NODE_TYPES.Program;
body: ProgramStatement[];
comments: Comment[] | undefined;
sourceType: 'module' | 'script';
tokens: Token[] | undefined;
parent?: never; // Program has no parent
}
// Union type of all possible nodes
type Node = Program | Statement | Expression | Declaration | /* ... all node types */;
}Essential type definitions used throughout the AST.
/**
* Source range information - array of two numbers representing start and end positions
* Both numbers are 0-based indices in the source code character array
*/
type Range = [number, number];
/**
* Source location information
*/
interface SourceLocation {
start: Position;
end: Position;
}
/**
* Position in source code
*/
interface Position {
/** Line number (1-indexed) */
line: number;
/** Column number on the line (0-indexed) */
column: number;
}
/**
* Comment node
*/
interface Comment extends NodeOrTokenData {
type: 'Block' | 'Line';
value: string;
}Type definitions for all statement node types.
// Variable declarations
interface VariableDeclaration extends BaseNode {
type: AST_NODE_TYPES.VariableDeclaration;
declarations: VariableDeclarator[];
kind: 'var' | 'let' | 'const' | 'using' | 'await using';
}
interface VariableDeclarator extends BaseNode {
type: AST_NODE_TYPES.VariableDeclarator;
id: BindingName;
init: Expression | null;
definite?: boolean;
}
// Function declarations
interface FunctionDeclaration extends BaseNode {
type: AST_NODE_TYPES.FunctionDeclaration;
id: Identifier | null;
params: Parameter[];
body: BlockStatement;
async: boolean;
generator: boolean;
declare?: boolean;
expression: false;
returnType?: TSTypeAnnotation;
typeParameters?: TSTypeParameterDeclaration;
}
// Control flow statements
interface IfStatement extends BaseNode {
type: AST_NODE_TYPES.IfStatement;
test: Expression;
consequent: Statement;
alternate: Statement | null;
}
interface ForStatement extends BaseNode {
type: AST_NODE_TYPES.ForStatement;
init: VariableDeclaration | Expression | null;
test: Expression | null;
update: Expression | null;
body: Statement;
}Type definitions for expression node types.
// Function expressions
interface ArrowFunctionExpression extends BaseNode {
type: AST_NODE_TYPES.ArrowFunctionExpression;
id: null;
params: Parameter[];
body: BlockStatement | Expression;
async: boolean;
generator: false;
expression: boolean;
returnType?: TSTypeAnnotation;
typeParameters?: TSTypeParameterDeclaration;
}
// Member access
interface MemberExpression extends BaseNode {
type: AST_NODE_TYPES.MemberExpression;
object: Expression;
property: Expression;
computed: boolean;
optional?: boolean;
}
// Function calls
interface CallExpression extends BaseNode {
type: AST_NODE_TYPES.CallExpression;
callee: Expression;
arguments: CallExpressionArgument[];
optional?: boolean;
typeArguments?: TSTypeParameterInstantiation;
}
// Binary operations
interface BinaryExpression extends BaseNode {
type: AST_NODE_TYPES.BinaryExpression;
left: Expression;
operator: BinaryOperator;
right: Expression;
}
type BinaryOperator =
| '==' | '!=' | '===' | '!=='
| '<' | '<=' | '>' | '>='
| '<<' | '>>' | '>>>'
| '+' | '-' | '*' | '/' | '%' | '**'
| '|' | '^' | '&'
| 'in' | 'instanceof';Type definitions for TypeScript language extensions.
// Type annotations
interface TSTypeAnnotation extends BaseNode {
type: AST_NODE_TYPES.TSTypeAnnotation;
typeAnnotation: TypeNode;
}
// Interface declarations
interface TSInterfaceDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSInterfaceDeclaration;
id: Identifier;
body: TSInterfaceBody;
extends?: TSInterfaceHeritage[];
typeParameters?: TSTypeParameterDeclaration;
abstract?: boolean;
declare?: boolean;
}
interface TSInterfaceBody extends BaseNode {
type: AST_NODE_TYPES.TSInterfaceBody;
body: TypeElement[];
}
// Type alias declarations
interface TSTypeAliasDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
id: Identifier;
typeAnnotation: TypeNode;
typeParameters?: TSTypeParameterDeclaration;
declare?: boolean;
}
// Enum declarations
interface TSEnumDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSEnumDeclaration;
id: Identifier;
body: TSEnumBody;
const?: boolean;
declare?: boolean;
}
// Type expressions
interface TSAsExpression extends BaseNode {
type: AST_NODE_TYPES.TSAsExpression;
expression: Expression;
typeAnnotation: TypeNode;
}
interface TSNonNullExpression extends BaseNode {
type: AST_NODE_TYPES.TSNonNullExpression;
expression: Expression;
}Common union types used throughout the AST.
// All possible nodes
type Node =
| Program
| Statement
| Expression
| Declaration
| TypeNode
| Comment;
// Statements
type Statement =
| BlockStatement
| VariableDeclaration
| FunctionDeclaration
| IfStatement
| ForStatement
| WhileStatement
| DoWhileStatement
| ReturnStatement
| BreakStatement
| ContinueStatement
| ThrowStatement
| TryStatement
| ExpressionStatement
/* ... all statement types */;
// Expressions
type Expression =
| Identifier
| Literal
| ArrowFunctionExpression
| FunctionExpression
| CallExpression
| MemberExpression
| BinaryExpression
| UnaryExpression
| UpdateExpression
| ConditionalExpression
/* ... all expression types */;
// TypeScript type nodes
type TypeNode =
| TSAnyKeyword
| TSStringKeyword
| TSNumberKeyword
| TSBooleanKeyword
| TSArrayType
| TSUnionType
| TSIntersectionType
| TSTypeReference
/* ... all type nodes */;Usage Examples:
import { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/types";
// Type-safe AST traversal
function traverseNode(node: TSESTree.Node): void {
switch (node.type) {
case AST_NODE_TYPES.FunctionDeclaration:
// TypeScript knows this is a FunctionDeclaration
console.log(`Function: ${node.id?.name}`);
if (node.returnType) {
console.log('Has return type annotation');
}
break;
case AST_NODE_TYPES.TSInterfaceDeclaration:
// TypeScript knows this is a TSInterfaceDeclaration
console.log(`Interface: ${node.id.name}`);
node.body.body.forEach(member => {
// Process interface members
});
break;
case AST_NODE_TYPES.CallExpression:
// TypeScript knows this is a CallExpression
if (node.typeArguments) {
console.log('Generic function call');
}
break;
}
}
// Parent relationship access
function getParentFunction(node: TSESTree.Node): TSESTree.FunctionDeclaration | null {
let current = node.parent;
while (current) {
if (current.type === AST_NODE_TYPES.FunctionDeclaration) {
return current; // TypeScript knows this is FunctionDeclaration
}
current = current.parent;
}
return null;
}
// Type predicate functions
function isFunctionLike(node: TSESTree.Node): node is TSESTree.FunctionLike {
return [
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.MethodDefinition
].includes(node.type);
}
function isTypeScriptNode(node: TSESTree.Node): boolean {
return node.type.startsWith('TS');
}
// Extract information from nodes
function extractFunctionInfo(node: TSESTree.FunctionDeclaration) {
return {
name: node.id?.name || '<anonymous>',
paramCount: node.params.length,
isAsync: node.async,
isGenerator: node.generator,
hasTypeParameters: !!node.typeParameters,
hasReturnType: !!node.returnType,
isDeclared: !!node.declare
};
}The TypeScript ESTree types include augmented parent relationships for all nodes:
Every AST node (except Program) has a strongly-typed parent property:
interface BaseNode {
parent: TSESTree.Node; // Points to the parent node
}
interface Program {
parent?: never; // Program has no parent
}Many nodes have specific parent type constraints:
interface CatchClause {
parent: TSESTree.TryStatement; // Always child of TryStatement
}
interface SwitchCase {
parent: TSESTree.SwitchStatement; // Always child of SwitchStatement
}
interface TSEnumMember {
parent: TSESTree.TSEnumBody; // Always child of TSEnumBody
}This enables type-safe parent access without runtime checks or type assertions.
Install with Tessl CLI
npx tessl i tessl/npm-typescript-eslint--types