A parser that converts TypeScript source code into an ESTree compatible form
npx @tessl/cli install tessl/npm-typescript-eslint--typescript-estree@8.42.0TypeScript ESTree is a parser that converts TypeScript source code into an ESTree-compatible Abstract Syntax Tree (AST) format. It serves as a crucial bridge between TypeScript's native compiler API and the ESTree AST specification used by JavaScript tooling ecosystems like ESLint. The parser handles TypeScript-specific syntax features including type annotations, interfaces, generics, decorators, and advanced TypeScript constructs while maintaining compatibility with ESLint's plugin architecture.
npm install @typescript-eslint/typescript-estreeimport { parse, parseAndGenerateServices } from "@typescript-eslint/typescript-estree";
import type { TSESTreeOptions, ParserServices } from "@typescript-eslint/typescript-estree";For CommonJS:
const { parse, parseAndGenerateServices } = require("@typescript-eslint/typescript-estree");import { parse, parseAndGenerateServices } from "@typescript-eslint/typescript-estree";
// Simple parsing without type information
const code = `const x: number = 42;`;
const ast = parse(code, {
loc: true,
range: true
});
// Full parsing with TypeScript services
const result = parseAndGenerateServices(code, {
loc: true,
range: true,
project: "./tsconfig.json"
});
console.log(result.ast.type); // "Program"
console.log(result.services.program !== null); // true if project providedTypeScript ESTree is built around several key components:
parse, parseAndGenerateServices) for different use casesPrimary parsing functions that convert TypeScript source code into ESTree-compatible AST format.
function parse<T extends TSESTreeOptions = TSESTreeOptions>(
code: string,
options?: T
): AST<T>;
function parseAndGenerateServices<T extends TSESTreeOptions = TSESTreeOptions>(
code: string | ts.SourceFile,
options: T
): ParseAndGenerateServicesResult<T>;Configuration options and services for controlling parsing behavior and accessing TypeScript type information.
interface TSESTreeOptions {
loc?: boolean;
range?: boolean;
tokens?: boolean;
comment?: boolean;
project?: boolean | string | string[] | null;
projectService?: boolean | ProjectServiceOptions;
filePath?: string;
jsx?: boolean;
// ... additional options
}
interface ParserServices {
program: ts.Program | null;
esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
tsNodeToESTreeNodeMap: ParserWeakMap<TSNode | TSToken, TSESTree.Node>;
// ... additional services when program available
}Functions for creating and managing TypeScript programs with sophisticated caching.
function createProgram(configFile: string): ts.Program;
function getCanonicalFileName(fileName: string): string;
function clearCaches(): void;Utility functions for working with TypeScript and ESTree AST nodes.
function simpleTraverse(
startingNode: TSESTree.Node,
options: SimpleTraverseOptions,
setParentPointers?: boolean
): void;
function getModifiers(
node: ts.Node | null | undefined,
includeIllegalModifiers?: boolean
): ts.Modifier[] | undefined;
function getScriptKind(filePath: string, jsx: boolean): ts.ScriptKind;Types and interfaces for working with ESTree-compatible TypeScript AST nodes and TypeScript integration.
type AST<T extends TSESTreeOptions> =
(T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}) &
(T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) &
TSESTree.Program;
interface ParseAndGenerateServicesResult<T extends TSESTreeOptions> {
ast: AST<T>;
services: ParserServices;
}// Core result types
type AST<T extends TSESTreeOptions> =
(T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}) &
(T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) &
TSESTree.Program;
interface ParseAndGenerateServicesResult<T extends TSESTreeOptions> {
ast: AST<T>;
services: ParserServices;
}
// Parser services union type
type ParserServices =
| ParserServicesWithoutTypeInformation
| ParserServicesWithTypeInformation;
// Error class for parsing errors
class TSError extends Error {
constructor(
message: string,
fileName: string,
location: {
start: { line: number; column: number; offset: number };
end: { line: number; column: number; offset: number };
}
);
}
// Version compatibility object
const typescriptVersionIsAtLeast: Record<'4.7' | '4.8' | '4.9' | '5.0' | '5.1' | '5.2' | '5.3' | '5.4', boolean>;