CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-typescript-eslint--experimental-utils

(Experimental) Utilities for working with TypeScript + ESLint together

Pending
Overview
Eval results
Files

ts-estree.mddocs/

TypeScript ESTree

AST node definitions and parser services for TypeScript syntax trees. This module provides comprehensive type definitions for all TypeScript and JavaScript AST nodes, plus integration services for accessing TypeScript compiler information.

Capabilities

AST Node Types

Enumeration of all supported AST node types in TypeScript ESTree.

/**
 * Enumeration of all AST node types supported by TypeScript ESTree
 */
enum AST_NODE_TYPES {
  // JavaScript nodes
  ArrayExpression = 'ArrayExpression',
  ArrayPattern = 'ArrayPattern', 
  ArrowFunctionExpression = 'ArrowFunctionExpression',
  AssignmentExpression = 'AssignmentExpression',
  AssignmentPattern = 'AssignmentPattern',
  AwaitExpression = 'AwaitExpression',
  BinaryExpression = 'BinaryExpression',
  BlockStatement = 'BlockStatement',
  BreakStatement = 'BreakStatement',
  CallExpression = 'CallExpression',
  CatchClause = 'CatchClause',
  ChainExpression = 'ChainExpression',
  ClassBody = 'ClassBody',
  ClassDeclaration = 'ClassDeclaration',
  ClassExpression = 'ClassExpression',
  ConditionalExpression = 'ConditionalExpression',
  ContinueStatement = 'ContinueStatement',
  DebuggerStatement = 'DebuggerStatement',
  DoWhileStatement = 'DoWhileStatement',
  EmptyStatement = 'EmptyStatement',
  ExportAllDeclaration = 'ExportAllDeclaration',
  ExportDefaultDeclaration = 'ExportDefaultDeclaration',
  ExportNamedDeclaration = 'ExportNamedDeclaration',
  ExportSpecifier = 'ExportSpecifier',
  ExpressionStatement = 'ExpressionStatement',
  ForInStatement = 'ForInStatement',
  ForOfStatement = 'ForOfStatement',
  ForStatement = 'ForStatement',
  FunctionDeclaration = 'FunctionDeclaration',
  FunctionExpression = 'FunctionExpression',
  Identifier = 'Identifier',
  IfStatement = 'IfStatement',
  ImportDeclaration = 'ImportDeclaration',
  ImportDefaultSpecifier = 'ImportDefaultSpecifier',
  ImportExpression = 'ImportExpression',
  ImportNamespaceSpecifier = 'ImportNamespaceSpecifier',
  ImportSpecifier = 'ImportSpecifier',
  JSXAttribute = 'JSXAttribute',
  JSXClosingElement = 'JSXClosingElement',
  JSXClosingFragment = 'JSXClosingFragment',
  JSXElement = 'JSXElement',
  JSXEmptyExpression = 'JSXEmptyExpression',
  JSXExpressionContainer = 'JSXExpressionContainer',
  JSXFragment = 'JSXFragment',
  JSXIdentifier = 'JSXIdentifier',
  JSXMemberExpression = 'JSXMemberExpression',
  JSXNamespacedName = 'JSXNamespacedName',
  JSXOpeningElement = 'JSXOpeningElement',
  JSXOpeningFragment = 'JSXOpeningFragment',
  JSXSpreadAttribute = 'JSXSpreadAttribute',
  JSXSpreadChild = 'JSXSpreadChild',
  JSXText = 'JSXText',
  LabeledStatement = 'LabeledStatement',
  Literal = 'Literal',
  LogicalExpression = 'LogicalExpression',
  MemberExpression = 'MemberExpression',
  MetaProperty = 'MetaProperty',
  MethodDefinition = 'MethodDefinition',
  NewExpression = 'NewExpression',
  ObjectExpression = 'ObjectExpression',
  ObjectPattern = 'ObjectPattern',
  PrivateIdentifier = 'PrivateIdentifier',
  Program = 'Program',
  Property = 'Property',
  PropertyDefinition = 'PropertyDefinition',
  RestElement = 'RestElement',
  ReturnStatement = 'ReturnStatement',
  SequenceExpression = 'SequenceExpression',
  SpreadElement = 'SpreadElement',
  StaticBlock = 'StaticBlock',
  Super = 'Super',
  SwitchCase = 'SwitchCase',
  SwitchStatement = 'SwitchStatement',
  TaggedTemplateExpression = 'TaggedTemplateExpression',
  TemplateElement = 'TemplateElement',
  TemplateLiteral = 'TemplateLiteral',
  ThisExpression = 'ThisExpression',
  ThrowStatement = 'ThrowStatement',
  TryStatement = 'TryStatement',
  UnaryExpression = 'UnaryExpression',
  UpdateExpression = 'UpdateExpression',
  VariableDeclaration = 'VariableDeclaration',
  VariableDeclarator = 'VariableDeclarator',
  WhileStatement = 'WhileStatement',
  WithStatement = 'WithStatement',
  YieldExpression = 'YieldExpression',

  // TypeScript-specific nodes
  TSAbstractKeyword = 'TSAbstractKeyword',
  TSAbstractMethodDefinition = 'TSAbstractMethodDefinition',
  TSAbstractPropertyDefinition = 'TSAbstractPropertyDefinition',
  TSAnyKeyword = 'TSAnyKeyword',
  TSArrayType = 'TSArrayType',
  TSAsExpression = 'TSAsExpression',
  TSBigIntKeyword = 'TSBigIntKeyword',
  TSBooleanKeyword = 'TSBooleanKeyword',
  TSCallSignatureDeclaration = 'TSCallSignatureDeclaration',
  TSClassImplements = 'TSClassImplements',
  TSConditionalType = 'TSConditionalType',
  TSConstructorType = 'TSConstructorType',
  TSConstructSignatureDeclaration = 'TSConstructSignatureDeclaration',
  TSDeclareFunction = 'TSDeclareFunction',
  TSDeclareKeyword = 'TSDeclareKeyword',
  TSEmptyBodyFunctionExpression = 'TSEmptyBodyFunctionExpression',
  TSEnumDeclaration = 'TSEnumDeclaration',
  TSEnumMember = 'TSEnumMember',
  TSExportAssignment = 'TSExportAssignment',
  TSExportKeyword = 'TSExportKeyword',
  TSExternalModuleReference = 'TSExternalModuleReference',
  TSFunctionType = 'TSFunctionType',
  TSImportEqualsDeclaration = 'TSImportEqualsDeclaration',
  TSImportType = 'TSImportType',
  TSIndexedAccessType = 'TSIndexedAccessType',
  TSIndexSignature = 'TSIndexSignature',
  TSInferType = 'TSInferType',
  TSInstantiationExpression = 'TSInstantiationExpression',
  TSInterfaceBody = 'TSInterfaceBody',
  TSInterfaceDeclaration = 'TSInterfaceDeclaration',
  TSInterfaceHeritage = 'TSInterfaceHeritage',
  TSIntersectionType = 'TSIntersectionType',
  TSIntrinsicKeyword = 'TSIntrinsicKeyword',
  TSLiteralType = 'TSLiteralType',
  TSMappedType = 'TSMappedType',
  TSMethodSignature = 'TSMethodSignature',
  TSModuleBlock = 'TSModuleBlock',
  TSModuleDeclaration = 'TSModuleDeclaration',
  TSNamedTupleMember = 'TSNamedTupleMember',
  TSNamespaceExportDeclaration = 'TSNamespaceExportDeclaration',
  TSNeverKeyword = 'TSNeverKeyword',
  TSNonNullExpression = 'TSNonNullExpression',
  TSNullKeyword = 'TSNullKeyword',
  TSNumberKeyword = 'TSNumberKeyword',
  TSObjectKeyword = 'TSObjectKeyword',
  TSOptionalType = 'TSOptionalType',
  TSParameterProperty = 'TSParameterProperty',
  TSPrivateKeyword = 'TSPrivateKeyword',
  TSPropertySignature = 'TSPropertySignature',
  TSProtectedKeyword = 'TSProtectedKeyword',
  TSPublicKeyword = 'TSPublicKeyword',
  TSQualifiedName = 'TSQualifiedName',
  TSReadonlyKeyword = 'TSReadonlyKeyword',
  TSRestType = 'TSRestType',
  TSSatisfiesExpression = 'TSSatisfiesExpression',
  TSStaticKeyword = 'TSStaticKeyword',
  TSStringKeyword = 'TSStringKeyword',
  TSSymbolKeyword = 'TSSymbolKeyword',
  TSTemplateLiteralType = 'TSTemplateLiteralType',
  TSThisType = 'TSThisType',
  TSTupleType = 'TSTupleType',
  TSTypeAliasDeclaration = 'TSTypeAliasDeclaration',
  TSTypeAnnotation = 'TSTypeAnnotation',
  TSTypeAssertion = 'TSTypeAssertion',
  TSTypeLiteral = 'TSTypeLiteral',
  TSTypeOperator = 'TSTypeOperator',
  TSTypeParameter = 'TSTypeParameter',
  TSTypeParameterDeclaration = 'TSTypeParameterDeclaration',
  TSTypeParameterInstantiation = 'TSTypeParameterInstantiation',
  TSTypePredicate = 'TSTypePredicate',
  TSTypeQuery = 'TSTypeQuery',
  TSTypeReference = 'TSTypeReference',
  TSUndefinedKeyword = 'TSUndefinedKeyword',
  TSUnionType = 'TSUnionType',
  TSUnknownKeyword = 'TSUnknownKeyword',
  TSVoidKeyword = 'TSVoidKeyword'
}

AST Token Types

Enumeration of all token types in TypeScript ESTree.

/**
 * Enumeration of all token types in TypeScript ESTree
 */
enum AST_TOKEN_TYPES {
  /** Boolean literal tokens (true, false) */
  Boolean = 'Boolean',
  /** Identifier tokens (variable names, etc.) */
  Identifier = 'Identifier',
  /** JSX identifier tokens */
  JSXIdentifier = 'JSXIdentifier',
  /** JSX text content */
  JSXText = 'JSXText',
  /** JavaScript keyword tokens (if, for, class, etc.) */
  Keyword = 'Keyword',
  /** Null literal token */
  Null = 'Null',
  /** Numeric literal tokens */
  Numeric = 'Numeric',
  /** Punctuator tokens (operators, delimiters) */
  Punctuator = 'Punctuator',
  /** Regular expression literal tokens */
  RegularExpression = 'RegularExpression',
  /** String literal tokens */
  String = 'String',
  /** Template literal tokens */
  Template = 'Template',
  /** Block comment tokens */
  Block = 'Block',
  /** Line comment tokens */
  Line = 'Line'
}

TypeScript ESTree Namespace

Complete TypeScript ESTree type definitions for all AST nodes.

/**
 * Complete TypeScript ESTree namespace containing all AST node definitions
 */
declare namespace TSESTree {
  // Base interfaces
  interface BaseNode {
    type: AST_NODE_TYPES;
    range: [number, number];
    loc: SourceLocation;
    parent?: Node;
  }

  interface SourceLocation {
    start: Position;
    end: Position;
  }

  interface Position {
    line: number;
    column: number;
  }

  // Union of all possible nodes
  type Node = 
    | ArrayExpression
    | ArrayPattern
    | ArrowFunctionExpression
    | AssignmentExpression
    | AssignmentPattern
    | AwaitExpression
    | BinaryExpression
    | BlockStatement
    | BreakStatement
    | CallExpression
    | CatchClause
    | ChainExpression
    | ClassBody
    | ClassDeclaration
    | ClassExpression
    | ConditionalExpression
    | ContinueStatement
    | DebuggerStatement
    | DoWhileStatement
    | EmptyStatement
    | ExportAllDeclaration
    | ExportDefaultDeclaration
    | ExportNamedDeclaration
    | ExportSpecifier
    | ExpressionStatement
    | ForInStatement
    | ForOfStatement
    | ForStatement
    | FunctionDeclaration
    | FunctionExpression
    | Identifier
    | IfStatement
    | ImportDeclaration
    | ImportDefaultSpecifier
    | ImportExpression
    | ImportNamespaceSpecifier
    | ImportSpecifier
    | LabeledStatement
    | Literal
    | LogicalExpression
    | MemberExpression
    | MetaProperty
    | MethodDefinition
    | NewExpression
    | ObjectExpression
    | ObjectPattern
    | PrivateIdentifier
    | Program
    | Property
    | PropertyDefinition
    | RestElement
    | ReturnStatement
    | SequenceExpression
    | SpreadElement
    | StaticBlock
    | Super
    | SwitchCase
    | SwitchStatement
    | TaggedTemplateExpression
    | TemplateElement
    | TemplateLiteral
    | ThisExpression
    | ThrowStatement
    | TryStatement
    | UnaryExpression
    | UpdateExpression
    | VariableDeclaration
    | VariableDeclarator
    | WhileStatement
    | WithStatement
    | YieldExpression
    // TypeScript nodes
    | TSAbstractKeyword
    | TSAbstractMethodDefinition
    | TSAbstractPropertyDefinition
    | TSAnyKeyword
    | TSArrayType
    | TSAsExpression
    | TSBigIntKeyword
    | TSBooleanKeyword
    | TSCallSignatureDeclaration
    | TSClassImplements
    | TSConditionalType
    | TSConstructorType
    | TSConstructSignatureDeclaration
    | TSDeclareFunction
    | TSDeclareKeyword
    | TSEmptyBodyFunctionExpression
    | TSEnumDeclaration
    | TSEnumMember
    | TSExportAssignment
    | TSExportKeyword
    | TSExternalModuleReference
    | TSFunctionType
    | TSImportEqualsDeclaration
    | TSImportType
    | TSIndexedAccessType
    | TSIndexSignature
    | TSInferType
    | TSInstantiationExpression
    | TSInterfaceBody
    | TSInterfaceDeclaration
    | TSInterfaceHeritage
    | TSIntersectionType
    | TSIntrinsicKeyword
    | TSLiteralType
    | TSMappedType
    | TSMethodSignature
    | TSModuleBlock
    | TSModuleDeclaration
    | TSNamedTupleMember
    | TSNamespaceExportDeclaration
    | TSNeverKeyword
    | TSNonNullExpression
    | TSNullKeyword
    | TSNumberKeyword
    | TSObjectKeyword
    | TSOptionalType
    | TSParameterProperty
    | TSPrivateKeyword
    | TSPropertySignature
    | TSProtectedKeyword
    | TSPublicKeyword
    | TSQualifiedName
    | TSReadonlyKeyword
    | TSRestType
    | TSSatisfiesExpression
    | TSStaticKeyword
    | TSStringKeyword
    | TSSymbolKeyword
    | TSTemplateLiteralType
    | TSThisType
    | TSTupleType
    | TSTypeAliasDeclaration
    | TSTypeAnnotation
    | TSTypeAssertion
    | TSTypeLiteral
    | TSTypeOperator
    | TSTypeParameter
    | TSTypeParameterDeclaration
    | TSTypeParameterInstantiation
    | TSTypePredicate
    | TSTypeQuery
    | TSTypeReference
    | TSUndefinedKeyword
    | TSUnionType
    | TSUnknownKeyword
    | TSVoidKeyword;

  // Function-like node union
  type FunctionLike = 
    | FunctionDeclaration
    | FunctionExpression
    | ArrowFunctionExpression
    | TSEmptyBodyFunctionExpression
    | TSDeclareFunction;

  // Expression union
  type Expression = 
    | ArrayExpression
    | ArrowFunctionExpression
    | AssignmentExpression
    | AwaitExpression
    | BinaryExpression
    | CallExpression
    | ChainExpression
    | ClassExpression
    | ConditionalExpression
    | FunctionExpression
    | Identifier
    | ImportExpression
    | Literal
    | LogicalExpression
    | MemberExpression
    | MetaProperty
    | NewExpression
    | ObjectExpression
    | SequenceExpression
    | Super
    | TaggedTemplateExpression
    | TemplateLiteral
    | ThisExpression
    | UnaryExpression
    | UpdateExpression
    | YieldExpression
    | TSAsExpression
    | TSInstantiationExpression
    | TSNonNullExpression
    | TSSatisfiesExpression
    | TSTypeAssertion;

  // Statement union
  type Statement = 
    | BlockStatement
    | BreakStatement
    | ClassDeclaration
    | ContinueStatement
    | DebuggerStatement
    | DoWhileStatement
    | EmptyStatement
    | ExportAllDeclaration
    | ExportDefaultDeclaration
    | ExportNamedDeclaration
    | ExpressionStatement
    | ForInStatement
    | ForOfStatement
    | ForStatement
    | FunctionDeclaration
    | IfStatement
    | ImportDeclaration
    | LabeledStatement
    | ReturnStatement
    | SwitchStatement
    | ThrowStatement
    | TryStatement
    | VariableDeclaration
    | WhileStatement
    | WithStatement
    | TSEnumDeclaration
    | TSExportAssignment
    | TSImportEqualsDeclaration
    | TSInterfaceDeclaration
    | TSModuleDeclaration
    | TSNamespaceExportDeclaration
    | TSTypeAliasDeclaration;

  // Key node interface examples (showing structure)
  interface Program extends BaseNode {
    type: AST_NODE_TYPES.Program;
    body: Statement[];
    sourceType: 'module' | 'script';
    comments?: Comment[];
    tokens?: Token[];
  }

  interface Identifier extends BaseNode {
    type: AST_NODE_TYPES.Identifier;
    name: string;
    typeAnnotation?: TSTypeAnnotation;
    optional?: boolean;
  }

  interface CallExpression extends BaseNode {
    type: AST_NODE_TYPES.CallExpression;
    callee: Expression;
    arguments: (Expression | SpreadElement)[];
    optional?: boolean;
    typeParameters?: TSTypeParameterInstantiation;
  }

  interface FunctionDeclaration extends BaseNode {
    type: AST_NODE_TYPES.FunctionDeclaration;
    id: Identifier;
    params: Parameter[];
    body: BlockStatement;
    generator?: boolean;
    async?: boolean;
    declare?: boolean;
    returnType?: TSTypeAnnotation;
    typeParameters?: TSTypeParameterDeclaration;
  }

  // TypeScript-specific examples
  interface TSInterfaceDeclaration extends BaseNode {
    type: AST_NODE_TYPES.TSInterfaceDeclaration;
    id: Identifier;
    body: TSInterfaceBody;
    extends?: TSInterfaceHeritage[];
    typeParameters?: TSTypeParameterDeclaration;
    declare?: boolean;
  }

  interface TSTypeAnnotation extends BaseNode {
    type: AST_NODE_TYPES.TSTypeAnnotation;
    typeAnnotation: TypeNode;
  }

  interface TSAsExpression extends BaseNode {
    type: AST_NODE_TYPES.TSAsExpression;
    expression: Expression;
    typeAnnotation: TypeNode;
  }

  // Token interfaces
  interface Token {
    type: string;
    value: string;
    range: [number, number];
    loc: SourceLocation;
  }

  interface Comment extends Token {
    type: 'Block' | 'Line';
  }

  interface BooleanToken extends Token {
    type: AST_TOKEN_TYPES.Boolean;
  }

  interface IdentifierToken extends Token {
    type: AST_TOKEN_TYPES.Identifier;
  }

  interface JSXIdentifierToken extends Token {
    type: AST_TOKEN_TYPES.JSXIdentifier;
  }

  interface JSXTextToken extends Token {
    type: AST_TOKEN_TYPES.JSXText;
  }

  interface KeywordToken extends Token {
    type: AST_TOKEN_TYPES.Keyword;
  }

  interface NullToken extends Token {
    type: AST_TOKEN_TYPES.Null;
  }

  interface NumericToken extends Token {
    type: AST_TOKEN_TYPES.Numeric;
  }

  interface PunctuatorToken extends Token {
    type: AST_TOKEN_TYPES.Punctuator;
  }

  interface RegularExpressionToken extends Token {
    type: AST_TOKEN_TYPES.RegularExpression;
  }

  interface StringToken extends Token {
    type: AST_TOKEN_TYPES.String;
  }

  interface TemplateToken extends Token {
    type: AST_TOKEN_TYPES.Template;
  }

  interface BlockComment extends Token {
    type: AST_TOKEN_TYPES.Block;
  }

  interface LineComment extends Token {
    type: AST_TOKEN_TYPES.Line;
  }

  // Union types for convenience
  type Parameter = AssignmentPattern | Identifier | ObjectPattern | ArrayPattern | RestElement | TSParameterProperty;
  type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName;
  type TypeNode = any; // Union of all TypeScript type nodes
  type ClassElement = MethodDefinition | PropertyDefinition | TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSIndexSignature;
  type TypeElement = TSCallSignatureDeclaration | TSConstructSignatureDeclaration | TSIndexSignature | TSMethodSignature | TSPropertySignature;
  type StringLiteral = Literal & { value: string };
  type NumericLiteral = Literal & { value: number };
  type ComputedPropertyName = Expression;
}

Parser Services

TypeScript compiler integration services for ESLint rules.

/**
 * Parser services providing access to TypeScript compiler information
 */
interface ParserServices {
  /** TypeScript program instance (null if not available) */
  program: ts.Program | null;
  
  /** Map from ESTree nodes to TypeScript nodes */
  esTreeNodeToTSNodeMap: WeakMap<TSESTree.Node, ts.Node | ts.Token>;
  
  /** Map from TypeScript nodes to ESTree nodes */
  tsNodeToESTreeNodeMap: WeakMap<ts.Node | ts.Token, TSESTree.Node>;
  
  /** Whether full TypeScript type information is available */
  hasFullTypeInformation: boolean;
  
  /**
   * Gets the TypeScript symbol at the given ESTree node location
   * @param node - ESTree node to get symbol for
   * @returns TypeScript symbol if available
   */
  getSymbolAtLocation(node: TSESTree.Node): ts.Symbol | undefined;
  
  /**
   * Gets the TypeScript type at the given ESTree node location
   * @param node - ESTree node to get type for
   * @returns TypeScript type information
   */
  getTypeAtLocation(node: TSESTree.Node): ts.Type;
}

Usage Examples:

import { TSESTree, TSESLint, ESLintUtils } from "@typescript-eslint/experimental-utils";

// Using AST node types
function processNode(node: TSESTree.Node): void {
  switch (node.type) {
    case TSESTree.AST_NODE_TYPES.FunctionDeclaration:
      // node is now typed as TSESTree.FunctionDeclaration
      console.log('Function name:', node.id?.name);
      break;
    case TSESTree.AST_NODE_TYPES.CallExpression:
      // node is now typed as TSESTree.CallExpression
      console.log('Call expression with', node.arguments.length, 'arguments');
      break;
  }
}

// Using parser services in a rule
const rule: TSESLint.RuleModule<'error', []> = {
  meta: {
    type: 'problem',
    messages: { error: 'Type error: {{message}}' },
    schema: []
  },
  create(context) {
    const services = ESLintUtils.getParserServices(context);
    const checker = services.program?.getTypeChecker();
    
    return {
      CallExpression(node: TSESTree.CallExpression) {
        if (checker && services.hasFullTypeInformation) {
          const tsNode = services.esTreeNodeToTSNodeMap.get(node);
          if (tsNode) {
            const type = checker.getTypeAtLocation(tsNode);
            const typeString = checker.typeToString(type);
            
            context.report({
              node,
              messageId: 'error',
              data: { message: `Called expression has type: ${typeString}` }
            });
          }
        }
      }
    };
  }
};

// Working with tokens
function analyzeTokens(sourceCode: TSESLint.SourceCode): void {
  const tokens = sourceCode.getTokens();
  
  tokens.forEach(token => {
    switch (token.type) {
      case TSESTree.AST_TOKEN_TYPES.Keyword:
        console.log('Found keyword:', token.value);
        break;
      case TSESTree.AST_TOKEN_TYPES.Identifier:
        console.log('Found identifier:', token.value);
        break;
      case TSESTree.AST_TOKEN_TYPES.Punctuator:
        console.log('Found punctuator:', token.value);
        break;
    }
  });
}

// Type-safe node checking
function isFunctionLike(node: TSESTree.Node): node is TSESTree.FunctionLike {
  return node.type === TSESTree.AST_NODE_TYPES.FunctionDeclaration ||
         node.type === TSESTree.AST_NODE_TYPES.FunctionExpression ||
         node.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression ||
         node.type === TSESTree.AST_NODE_TYPES.TSEmptyBodyFunctionExpression ||
         node.type === TSESTree.AST_NODE_TYPES.TSDeclareFunction;
}

// TypeScript-specific node handling
function processTypeAnnotation(node: TSESTree.TSTypeAnnotation): void {
  const typeNode = node.typeAnnotation;
  
  switch (typeNode.type) {
    case TSESTree.AST_NODE_TYPES.TSStringKeyword:
      console.log('String type annotation');
      break;
    case TSESTree.AST_NODE_TYPES.TSNumberKeyword:
      console.log('Number type annotation');
      break;
    case TSESTree.AST_NODE_TYPES.TSUnionType:
      console.log('Union type with', typeNode.types.length, 'members');
      break;
  }
}

Node Interface Examples

Key TypeScript ESTree node interfaces demonstrating the structure:

// Core JavaScript nodes
interface ArrayExpression extends BaseNode {
  type: AST_NODE_TYPES.ArrayExpression;
  elements: (Expression | SpreadElement | null)[];
}

interface ObjectExpression extends BaseNode {
  type: AST_NODE_TYPES.ObjectExpression;
  properties: (Property | SpreadElement)[];
}

interface Property extends BaseNode {
  type: AST_NODE_TYPES.Property;
  key: PropertyName;
  value: Expression | Pattern;
  kind: 'init' | 'get' | 'set';
  method: boolean;
  shorthand: boolean;
  computed: boolean;
}

interface MethodDefinition extends BaseNode {
  type: AST_NODE_TYPES.MethodDefinition;
  key: PropertyName;
  value: FunctionExpression | TSEmptyBodyFunctionExpression;
  kind: 'constructor' | 'method' | 'get' | 'set';
  computed: boolean;
  static: boolean;
  override?: boolean;
  optional?: boolean;
  accessibility?: 'public' | 'protected' | 'private';
  decorators?: Decorator[];
}

// TypeScript-specific nodes
interface TSInterfaceBody extends BaseNode {
  type: AST_NODE_TYPES.TSInterfaceBody;
  body: TypeElement[];
}

interface TSPropertySignature extends BaseNode {
  type: AST_NODE_TYPES.TSPropertySignature;
  key: PropertyName;
  typeAnnotation?: TSTypeAnnotation;
  optional?: boolean;
  computed?: boolean;
  readonly?: boolean;
}

interface TSMethodSignature extends BaseNode {
  type: AST_NODE_TYPES.TSMethodSignature;
  key: PropertyName;
  params: Parameter[];
  returnType?: TSTypeAnnotation;
  computed?: boolean;
  optional?: boolean;
  kind: 'method' | 'get' | 'set';
  typeParameters?: TSTypeParameterDeclaration;
}

interface TSTypeReference extends BaseNode {
  type: AST_NODE_TYPES.TSTypeReference;
  typeName: EntityName;
  typeParameters?: TSTypeParameterInstantiation;
}

interface TSUnionType extends BaseNode {
  type: AST_NODE_TYPES.TSUnionType;
  types: TypeNode[];
}

interface TSIntersectionType extends BaseNode {
  type: AST_NODE_TYPES.TSIntersectionType;
  types: TypeNode[];
}

Install with Tessl CLI

npx tessl i tessl/npm-typescript-eslint--experimental-utils

docs

ast-utils.md

eslint-utils.md

index.md

json-schema.md

scope-analysis.md

ts-eslint.md

ts-estree.md

tile.json