Type definitions for the TypeScript-ESTree AST specification, including parser options and AST node types
npx @tessl/cli install tessl/npm-typescript-eslint--types@8.42.0@typescript-eslint/types provides comprehensive TypeScript type definitions for the TypeScript-ESTree Abstract Syntax Tree (AST) specification. As an internal utility package within the typescript-eslint ecosystem, it serves as the foundation for type-safe parsing, analysis, and linting of TypeScript code across all related tools.
npm install @typescript-eslint/typesimport { AST_NODE_TYPES, AST_TOKEN_TYPES, ParserOptions, TSESTree, Lib } from "@typescript-eslint/types";For CommonJS:
const { AST_NODE_TYPES, AST_TOKEN_TYPES, ParserOptions, TSESTree, Lib } = require("@typescript-eslint/types");import { AST_NODE_TYPES, ParserOptions, TSESTree } from "@typescript-eslint/types";
// Check AST node types
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
// TypeScript now knows this is a function declaration node
console.log(node.id?.name);
}
// Configure parser options
const parserOptions: ParserOptions = {
ecmaVersion: 2022,
sourceType: "module",
project: "./tsconfig.json",
lib: ["es2022", "dom"]
};
// Work with strongly-typed AST nodes
function processNode(node: TSESTree.Node): void {
switch (node.type) {
case AST_NODE_TYPES.VariableDeclaration:
// TypeScript provides full type safety
node.declarations.forEach(declarator => {
if (declarator.id.type === AST_NODE_TYPES.Identifier) {
console.log(`Variable: ${declarator.id.name}`);
}
});
break;
}
}@typescript-eslint/types is built around several key components:
Comprehensive enumeration of all AST node types for JavaScript and TypeScript, enabling type-safe node identification and processing.
enum AST_NODE_TYPES {
// Standard JavaScript nodes
Program = 'Program',
Identifier = 'Identifier',
Literal = 'Literal',
FunctionDeclaration = 'FunctionDeclaration',
// ... 172 total node types
// TypeScript-specific nodes
TSInterfaceDeclaration = 'TSInterfaceDeclaration',
TSTypeAnnotation = 'TSTypeAnnotation',
TSAsExpression = 'TSAsExpression',
// ... and many more
}Enumeration of lexical token types for parsing and syntax highlighting.
enum AST_TOKEN_TYPES {
Boolean = 'Boolean',
Identifier = 'Identifier',
Keyword = 'Keyword',
Null = 'Null',
Numeric = 'Numeric',
Punctuator = 'Punctuator',
RegularExpression = 'RegularExpression',
String = 'String',
Template = 'Template',
Block = 'Block', // Block comment
Line = 'Line', // Line comment
// ... 18 total token types
}Comprehensive configuration interfaces for the TypeScript parser, including ECMAScript version settings, project configuration, and TypeScript-specific options.
interface ParserOptions {
// ECMAScript configuration
ecmaVersion?: EcmaVersion;
sourceType?: SourceType;
// TypeScript project configuration
project?: boolean | string | string[] | null;
projectService?: boolean | ProjectServiceOptions;
tsconfigRootDir?: string;
// Parser features
jsxPragma?: string | null;
jsxFragmentName?: string | null;
lib?: Lib[];
// Debug and optimization
debugLevel?: DebugLevel;
errorOnUnknownASTType?: boolean;
// ... 25+ additional options
}Union type defining all available TypeScript library targets for compilation and type checking.
type Lib =
| 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018'
| 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024'
| 'esnext' | 'dom' | 'webworker' | 'scripthost'
| 'decorators' | 'decorators.legacy'
// ... 114 total library targetsComplete type definitions for all AST node structures with parent relationship augmentations, providing strongly-typed access to the entire syntax tree.
declare namespace TSESTree {
interface NodeOrTokenData {
type: string;
loc: SourceLocation;
range: Range;
}
interface BaseNode extends NodeOrTokenData {
type: AST_NODE_TYPES;
parent: Node; // Added by @typescript-eslint/types package
}
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
}
interface FunctionDeclaration extends BaseNode {
type: AST_NODE_TYPES.FunctionDeclaration;
id: Identifier | null;
params: Parameter[];
body: BlockStatement;
// ... complete interface definitions
}
// ... interfaces for all 172 node types
}