or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-utils.mdeslint-utils.mdindex.mdjson-schema.mdscope-analysis.mdts-eslint.mdts-estree.md

ts-estree.mddocs/

0

# TypeScript ESTree

1

2

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.

3

4

## Capabilities

5

6

### AST Node Types

7

8

Enumeration of all supported AST node types in TypeScript ESTree.

9

10

```typescript { .api }

11

/**

12

* Enumeration of all AST node types supported by TypeScript ESTree

13

*/

14

enum AST_NODE_TYPES {

15

// JavaScript nodes

16

ArrayExpression = 'ArrayExpression',

17

ArrayPattern = 'ArrayPattern',

18

ArrowFunctionExpression = 'ArrowFunctionExpression',

19

AssignmentExpression = 'AssignmentExpression',

20

AssignmentPattern = 'AssignmentPattern',

21

AwaitExpression = 'AwaitExpression',

22

BinaryExpression = 'BinaryExpression',

23

BlockStatement = 'BlockStatement',

24

BreakStatement = 'BreakStatement',

25

CallExpression = 'CallExpression',

26

CatchClause = 'CatchClause',

27

ChainExpression = 'ChainExpression',

28

ClassBody = 'ClassBody',

29

ClassDeclaration = 'ClassDeclaration',

30

ClassExpression = 'ClassExpression',

31

ConditionalExpression = 'ConditionalExpression',

32

ContinueStatement = 'ContinueStatement',

33

DebuggerStatement = 'DebuggerStatement',

34

DoWhileStatement = 'DoWhileStatement',

35

EmptyStatement = 'EmptyStatement',

36

ExportAllDeclaration = 'ExportAllDeclaration',

37

ExportDefaultDeclaration = 'ExportDefaultDeclaration',

38

ExportNamedDeclaration = 'ExportNamedDeclaration',

39

ExportSpecifier = 'ExportSpecifier',

40

ExpressionStatement = 'ExpressionStatement',

41

ForInStatement = 'ForInStatement',

42

ForOfStatement = 'ForOfStatement',

43

ForStatement = 'ForStatement',

44

FunctionDeclaration = 'FunctionDeclaration',

45

FunctionExpression = 'FunctionExpression',

46

Identifier = 'Identifier',

47

IfStatement = 'IfStatement',

48

ImportDeclaration = 'ImportDeclaration',

49

ImportDefaultSpecifier = 'ImportDefaultSpecifier',

50

ImportExpression = 'ImportExpression',

51

ImportNamespaceSpecifier = 'ImportNamespaceSpecifier',

52

ImportSpecifier = 'ImportSpecifier',

53

JSXAttribute = 'JSXAttribute',

54

JSXClosingElement = 'JSXClosingElement',

55

JSXClosingFragment = 'JSXClosingFragment',

56

JSXElement = 'JSXElement',

57

JSXEmptyExpression = 'JSXEmptyExpression',

58

JSXExpressionContainer = 'JSXExpressionContainer',

59

JSXFragment = 'JSXFragment',

60

JSXIdentifier = 'JSXIdentifier',

61

JSXMemberExpression = 'JSXMemberExpression',

62

JSXNamespacedName = 'JSXNamespacedName',

63

JSXOpeningElement = 'JSXOpeningElement',

64

JSXOpeningFragment = 'JSXOpeningFragment',

65

JSXSpreadAttribute = 'JSXSpreadAttribute',

66

JSXSpreadChild = 'JSXSpreadChild',

67

JSXText = 'JSXText',

68

LabeledStatement = 'LabeledStatement',

69

Literal = 'Literal',

70

LogicalExpression = 'LogicalExpression',

71

MemberExpression = 'MemberExpression',

72

MetaProperty = 'MetaProperty',

73

MethodDefinition = 'MethodDefinition',

74

NewExpression = 'NewExpression',

75

ObjectExpression = 'ObjectExpression',

76

ObjectPattern = 'ObjectPattern',

77

PrivateIdentifier = 'PrivateIdentifier',

78

Program = 'Program',

79

Property = 'Property',

80

PropertyDefinition = 'PropertyDefinition',

81

RestElement = 'RestElement',

82

ReturnStatement = 'ReturnStatement',

83

SequenceExpression = 'SequenceExpression',

84

SpreadElement = 'SpreadElement',

85

StaticBlock = 'StaticBlock',

86

Super = 'Super',

87

SwitchCase = 'SwitchCase',

88

SwitchStatement = 'SwitchStatement',

89

TaggedTemplateExpression = 'TaggedTemplateExpression',

90

TemplateElement = 'TemplateElement',

91

TemplateLiteral = 'TemplateLiteral',

92

ThisExpression = 'ThisExpression',

93

ThrowStatement = 'ThrowStatement',

94

TryStatement = 'TryStatement',

95

UnaryExpression = 'UnaryExpression',

96

UpdateExpression = 'UpdateExpression',

97

VariableDeclaration = 'VariableDeclaration',

98

VariableDeclarator = 'VariableDeclarator',

99

WhileStatement = 'WhileStatement',

100

WithStatement = 'WithStatement',

101

YieldExpression = 'YieldExpression',

102

103

// TypeScript-specific nodes

104

TSAbstractKeyword = 'TSAbstractKeyword',

105

TSAbstractMethodDefinition = 'TSAbstractMethodDefinition',

106

TSAbstractPropertyDefinition = 'TSAbstractPropertyDefinition',

107

TSAnyKeyword = 'TSAnyKeyword',

108

TSArrayType = 'TSArrayType',

109

TSAsExpression = 'TSAsExpression',

110

TSBigIntKeyword = 'TSBigIntKeyword',

111

TSBooleanKeyword = 'TSBooleanKeyword',

112

TSCallSignatureDeclaration = 'TSCallSignatureDeclaration',

113

TSClassImplements = 'TSClassImplements',

114

TSConditionalType = 'TSConditionalType',

115

TSConstructorType = 'TSConstructorType',

116

TSConstructSignatureDeclaration = 'TSConstructSignatureDeclaration',

117

TSDeclareFunction = 'TSDeclareFunction',

118

TSDeclareKeyword = 'TSDeclareKeyword',

119

TSEmptyBodyFunctionExpression = 'TSEmptyBodyFunctionExpression',

120

TSEnumDeclaration = 'TSEnumDeclaration',

121

TSEnumMember = 'TSEnumMember',

122

TSExportAssignment = 'TSExportAssignment',

123

TSExportKeyword = 'TSExportKeyword',

124

TSExternalModuleReference = 'TSExternalModuleReference',

125

TSFunctionType = 'TSFunctionType',

126

TSImportEqualsDeclaration = 'TSImportEqualsDeclaration',

127

TSImportType = 'TSImportType',

128

TSIndexedAccessType = 'TSIndexedAccessType',

129

TSIndexSignature = 'TSIndexSignature',

130

TSInferType = 'TSInferType',

131

TSInstantiationExpression = 'TSInstantiationExpression',

132

TSInterfaceBody = 'TSInterfaceBody',

133

TSInterfaceDeclaration = 'TSInterfaceDeclaration',

134

TSInterfaceHeritage = 'TSInterfaceHeritage',

135

TSIntersectionType = 'TSIntersectionType',

136

TSIntrinsicKeyword = 'TSIntrinsicKeyword',

137

TSLiteralType = 'TSLiteralType',

138

TSMappedType = 'TSMappedType',

139

TSMethodSignature = 'TSMethodSignature',

140

TSModuleBlock = 'TSModuleBlock',

141

TSModuleDeclaration = 'TSModuleDeclaration',

142

TSNamedTupleMember = 'TSNamedTupleMember',

143

TSNamespaceExportDeclaration = 'TSNamespaceExportDeclaration',

144

TSNeverKeyword = 'TSNeverKeyword',

145

TSNonNullExpression = 'TSNonNullExpression',

146

TSNullKeyword = 'TSNullKeyword',

147

TSNumberKeyword = 'TSNumberKeyword',

148

TSObjectKeyword = 'TSObjectKeyword',

149

TSOptionalType = 'TSOptionalType',

150

TSParameterProperty = 'TSParameterProperty',

151

TSPrivateKeyword = 'TSPrivateKeyword',

152

TSPropertySignature = 'TSPropertySignature',

153

TSProtectedKeyword = 'TSProtectedKeyword',

154

TSPublicKeyword = 'TSPublicKeyword',

155

TSQualifiedName = 'TSQualifiedName',

156

TSReadonlyKeyword = 'TSReadonlyKeyword',

157

TSRestType = 'TSRestType',

158

TSSatisfiesExpression = 'TSSatisfiesExpression',

159

TSStaticKeyword = 'TSStaticKeyword',

160

TSStringKeyword = 'TSStringKeyword',

161

TSSymbolKeyword = 'TSSymbolKeyword',

162

TSTemplateLiteralType = 'TSTemplateLiteralType',

163

TSThisType = 'TSThisType',

164

TSTupleType = 'TSTupleType',

165

TSTypeAliasDeclaration = 'TSTypeAliasDeclaration',

166

TSTypeAnnotation = 'TSTypeAnnotation',

167

TSTypeAssertion = 'TSTypeAssertion',

168

TSTypeLiteral = 'TSTypeLiteral',

169

TSTypeOperator = 'TSTypeOperator',

170

TSTypeParameter = 'TSTypeParameter',

171

TSTypeParameterDeclaration = 'TSTypeParameterDeclaration',

172

TSTypeParameterInstantiation = 'TSTypeParameterInstantiation',

173

TSTypePredicate = 'TSTypePredicate',

174

TSTypeQuery = 'TSTypeQuery',

175

TSTypeReference = 'TSTypeReference',

176

TSUndefinedKeyword = 'TSUndefinedKeyword',

177

TSUnionType = 'TSUnionType',

178

TSUnknownKeyword = 'TSUnknownKeyword',

179

TSVoidKeyword = 'TSVoidKeyword'

180

}

181

```

182

183

### AST Token Types

184

185

Enumeration of all token types in TypeScript ESTree.

186

187

```typescript { .api }

188

/**

189

* Enumeration of all token types in TypeScript ESTree

190

*/

191

enum AST_TOKEN_TYPES {

192

/** Boolean literal tokens (true, false) */

193

Boolean = 'Boolean',

194

/** Identifier tokens (variable names, etc.) */

195

Identifier = 'Identifier',

196

/** JSX identifier tokens */

197

JSXIdentifier = 'JSXIdentifier',

198

/** JSX text content */

199

JSXText = 'JSXText',

200

/** JavaScript keyword tokens (if, for, class, etc.) */

201

Keyword = 'Keyword',

202

/** Null literal token */

203

Null = 'Null',

204

/** Numeric literal tokens */

205

Numeric = 'Numeric',

206

/** Punctuator tokens (operators, delimiters) */

207

Punctuator = 'Punctuator',

208

/** Regular expression literal tokens */

209

RegularExpression = 'RegularExpression',

210

/** String literal tokens */

211

String = 'String',

212

/** Template literal tokens */

213

Template = 'Template',

214

/** Block comment tokens */

215

Block = 'Block',

216

/** Line comment tokens */

217

Line = 'Line'

218

}

219

```

220

221

### TypeScript ESTree Namespace

222

223

Complete TypeScript ESTree type definitions for all AST nodes.

224

225

```typescript { .api }

226

/**

227

* Complete TypeScript ESTree namespace containing all AST node definitions

228

*/

229

declare namespace TSESTree {

230

// Base interfaces

231

interface BaseNode {

232

type: AST_NODE_TYPES;

233

range: [number, number];

234

loc: SourceLocation;

235

parent?: Node;

236

}

237

238

interface SourceLocation {

239

start: Position;

240

end: Position;

241

}

242

243

interface Position {

244

line: number;

245

column: number;

246

}

247

248

// Union of all possible nodes

249

type Node =

250

| ArrayExpression

251

| ArrayPattern

252

| ArrowFunctionExpression

253

| AssignmentExpression

254

| AssignmentPattern

255

| AwaitExpression

256

| BinaryExpression

257

| BlockStatement

258

| BreakStatement

259

| CallExpression

260

| CatchClause

261

| ChainExpression

262

| ClassBody

263

| ClassDeclaration

264

| ClassExpression

265

| ConditionalExpression

266

| ContinueStatement

267

| DebuggerStatement

268

| DoWhileStatement

269

| EmptyStatement

270

| ExportAllDeclaration

271

| ExportDefaultDeclaration

272

| ExportNamedDeclaration

273

| ExportSpecifier

274

| ExpressionStatement

275

| ForInStatement

276

| ForOfStatement

277

| ForStatement

278

| FunctionDeclaration

279

| FunctionExpression

280

| Identifier

281

| IfStatement

282

| ImportDeclaration

283

| ImportDefaultSpecifier

284

| ImportExpression

285

| ImportNamespaceSpecifier

286

| ImportSpecifier

287

| LabeledStatement

288

| Literal

289

| LogicalExpression

290

| MemberExpression

291

| MetaProperty

292

| MethodDefinition

293

| NewExpression

294

| ObjectExpression

295

| ObjectPattern

296

| PrivateIdentifier

297

| Program

298

| Property

299

| PropertyDefinition

300

| RestElement

301

| ReturnStatement

302

| SequenceExpression

303

| SpreadElement

304

| StaticBlock

305

| Super

306

| SwitchCase

307

| SwitchStatement

308

| TaggedTemplateExpression

309

| TemplateElement

310

| TemplateLiteral

311

| ThisExpression

312

| ThrowStatement

313

| TryStatement

314

| UnaryExpression

315

| UpdateExpression

316

| VariableDeclaration

317

| VariableDeclarator

318

| WhileStatement

319

| WithStatement

320

| YieldExpression

321

// TypeScript nodes

322

| TSAbstractKeyword

323

| TSAbstractMethodDefinition

324

| TSAbstractPropertyDefinition

325

| TSAnyKeyword

326

| TSArrayType

327

| TSAsExpression

328

| TSBigIntKeyword

329

| TSBooleanKeyword

330

| TSCallSignatureDeclaration

331

| TSClassImplements

332

| TSConditionalType

333

| TSConstructorType

334

| TSConstructSignatureDeclaration

335

| TSDeclareFunction

336

| TSDeclareKeyword

337

| TSEmptyBodyFunctionExpression

338

| TSEnumDeclaration

339

| TSEnumMember

340

| TSExportAssignment

341

| TSExportKeyword

342

| TSExternalModuleReference

343

| TSFunctionType

344

| TSImportEqualsDeclaration

345

| TSImportType

346

| TSIndexedAccessType

347

| TSIndexSignature

348

| TSInferType

349

| TSInstantiationExpression

350

| TSInterfaceBody

351

| TSInterfaceDeclaration

352

| TSInterfaceHeritage

353

| TSIntersectionType

354

| TSIntrinsicKeyword

355

| TSLiteralType

356

| TSMappedType

357

| TSMethodSignature

358

| TSModuleBlock

359

| TSModuleDeclaration

360

| TSNamedTupleMember

361

| TSNamespaceExportDeclaration

362

| TSNeverKeyword

363

| TSNonNullExpression

364

| TSNullKeyword

365

| TSNumberKeyword

366

| TSObjectKeyword

367

| TSOptionalType

368

| TSParameterProperty

369

| TSPrivateKeyword

370

| TSPropertySignature

371

| TSProtectedKeyword

372

| TSPublicKeyword

373

| TSQualifiedName

374

| TSReadonlyKeyword

375

| TSRestType

376

| TSSatisfiesExpression

377

| TSStaticKeyword

378

| TSStringKeyword

379

| TSSymbolKeyword

380

| TSTemplateLiteralType

381

| TSThisType

382

| TSTupleType

383

| TSTypeAliasDeclaration

384

| TSTypeAnnotation

385

| TSTypeAssertion

386

| TSTypeLiteral

387

| TSTypeOperator

388

| TSTypeParameter

389

| TSTypeParameterDeclaration

390

| TSTypeParameterInstantiation

391

| TSTypePredicate

392

| TSTypeQuery

393

| TSTypeReference

394

| TSUndefinedKeyword

395

| TSUnionType

396

| TSUnknownKeyword

397

| TSVoidKeyword;

398

399

// Function-like node union

400

type FunctionLike =

401

| FunctionDeclaration

402

| FunctionExpression

403

| ArrowFunctionExpression

404

| TSEmptyBodyFunctionExpression

405

| TSDeclareFunction;

406

407

// Expression union

408

type Expression =

409

| ArrayExpression

410

| ArrowFunctionExpression

411

| AssignmentExpression

412

| AwaitExpression

413

| BinaryExpression

414

| CallExpression

415

| ChainExpression

416

| ClassExpression

417

| ConditionalExpression

418

| FunctionExpression

419

| Identifier

420

| ImportExpression

421

| Literal

422

| LogicalExpression

423

| MemberExpression

424

| MetaProperty

425

| NewExpression

426

| ObjectExpression

427

| SequenceExpression

428

| Super

429

| TaggedTemplateExpression

430

| TemplateLiteral

431

| ThisExpression

432

| UnaryExpression

433

| UpdateExpression

434

| YieldExpression

435

| TSAsExpression

436

| TSInstantiationExpression

437

| TSNonNullExpression

438

| TSSatisfiesExpression

439

| TSTypeAssertion;

440

441

// Statement union

442

type Statement =

443

| BlockStatement

444

| BreakStatement

445

| ClassDeclaration

446

| ContinueStatement

447

| DebuggerStatement

448

| DoWhileStatement

449

| EmptyStatement

450

| ExportAllDeclaration

451

| ExportDefaultDeclaration

452

| ExportNamedDeclaration

453

| ExpressionStatement

454

| ForInStatement

455

| ForOfStatement

456

| ForStatement

457

| FunctionDeclaration

458

| IfStatement

459

| ImportDeclaration

460

| LabeledStatement

461

| ReturnStatement

462

| SwitchStatement

463

| ThrowStatement

464

| TryStatement

465

| VariableDeclaration

466

| WhileStatement

467

| WithStatement

468

| TSEnumDeclaration

469

| TSExportAssignment

470

| TSImportEqualsDeclaration

471

| TSInterfaceDeclaration

472

| TSModuleDeclaration

473

| TSNamespaceExportDeclaration

474

| TSTypeAliasDeclaration;

475

476

// Key node interface examples (showing structure)

477

interface Program extends BaseNode {

478

type: AST_NODE_TYPES.Program;

479

body: Statement[];

480

sourceType: 'module' | 'script';

481

comments?: Comment[];

482

tokens?: Token[];

483

}

484

485

interface Identifier extends BaseNode {

486

type: AST_NODE_TYPES.Identifier;

487

name: string;

488

typeAnnotation?: TSTypeAnnotation;

489

optional?: boolean;

490

}

491

492

interface CallExpression extends BaseNode {

493

type: AST_NODE_TYPES.CallExpression;

494

callee: Expression;

495

arguments: (Expression | SpreadElement)[];

496

optional?: boolean;

497

typeParameters?: TSTypeParameterInstantiation;

498

}

499

500

interface FunctionDeclaration extends BaseNode {

501

type: AST_NODE_TYPES.FunctionDeclaration;

502

id: Identifier;

503

params: Parameter[];

504

body: BlockStatement;

505

generator?: boolean;

506

async?: boolean;

507

declare?: boolean;

508

returnType?: TSTypeAnnotation;

509

typeParameters?: TSTypeParameterDeclaration;

510

}

511

512

// TypeScript-specific examples

513

interface TSInterfaceDeclaration extends BaseNode {

514

type: AST_NODE_TYPES.TSInterfaceDeclaration;

515

id: Identifier;

516

body: TSInterfaceBody;

517

extends?: TSInterfaceHeritage[];

518

typeParameters?: TSTypeParameterDeclaration;

519

declare?: boolean;

520

}

521

522

interface TSTypeAnnotation extends BaseNode {

523

type: AST_NODE_TYPES.TSTypeAnnotation;

524

typeAnnotation: TypeNode;

525

}

526

527

interface TSAsExpression extends BaseNode {

528

type: AST_NODE_TYPES.TSAsExpression;

529

expression: Expression;

530

typeAnnotation: TypeNode;

531

}

532

533

// Token interfaces

534

interface Token {

535

type: string;

536

value: string;

537

range: [number, number];

538

loc: SourceLocation;

539

}

540

541

interface Comment extends Token {

542

type: 'Block' | 'Line';

543

}

544

545

interface BooleanToken extends Token {

546

type: AST_TOKEN_TYPES.Boolean;

547

}

548

549

interface IdentifierToken extends Token {

550

type: AST_TOKEN_TYPES.Identifier;

551

}

552

553

interface JSXIdentifierToken extends Token {

554

type: AST_TOKEN_TYPES.JSXIdentifier;

555

}

556

557

interface JSXTextToken extends Token {

558

type: AST_TOKEN_TYPES.JSXText;

559

}

560

561

interface KeywordToken extends Token {

562

type: AST_TOKEN_TYPES.Keyword;

563

}

564

565

interface NullToken extends Token {

566

type: AST_TOKEN_TYPES.Null;

567

}

568

569

interface NumericToken extends Token {

570

type: AST_TOKEN_TYPES.Numeric;

571

}

572

573

interface PunctuatorToken extends Token {

574

type: AST_TOKEN_TYPES.Punctuator;

575

}

576

577

interface RegularExpressionToken extends Token {

578

type: AST_TOKEN_TYPES.RegularExpression;

579

}

580

581

interface StringToken extends Token {

582

type: AST_TOKEN_TYPES.String;

583

}

584

585

interface TemplateToken extends Token {

586

type: AST_TOKEN_TYPES.Template;

587

}

588

589

interface BlockComment extends Token {

590

type: AST_TOKEN_TYPES.Block;

591

}

592

593

interface LineComment extends Token {

594

type: AST_TOKEN_TYPES.Line;

595

}

596

597

// Union types for convenience

598

type Parameter = AssignmentPattern | Identifier | ObjectPattern | ArrayPattern | RestElement | TSParameterProperty;

599

type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName;

600

type TypeNode = any; // Union of all TypeScript type nodes

601

type ClassElement = MethodDefinition | PropertyDefinition | TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSIndexSignature;

602

type TypeElement = TSCallSignatureDeclaration | TSConstructSignatureDeclaration | TSIndexSignature | TSMethodSignature | TSPropertySignature;

603

type StringLiteral = Literal & { value: string };

604

type NumericLiteral = Literal & { value: number };

605

type ComputedPropertyName = Expression;

606

}

607

```

608

609

### Parser Services

610

611

TypeScript compiler integration services for ESLint rules.

612

613

```typescript { .api }

614

/**

615

* Parser services providing access to TypeScript compiler information

616

*/

617

interface ParserServices {

618

/** TypeScript program instance (null if not available) */

619

program: ts.Program | null;

620

621

/** Map from ESTree nodes to TypeScript nodes */

622

esTreeNodeToTSNodeMap: WeakMap<TSESTree.Node, ts.Node | ts.Token>;

623

624

/** Map from TypeScript nodes to ESTree nodes */

625

tsNodeToESTreeNodeMap: WeakMap<ts.Node | ts.Token, TSESTree.Node>;

626

627

/** Whether full TypeScript type information is available */

628

hasFullTypeInformation: boolean;

629

630

/**

631

* Gets the TypeScript symbol at the given ESTree node location

632

* @param node - ESTree node to get symbol for

633

* @returns TypeScript symbol if available

634

*/

635

getSymbolAtLocation(node: TSESTree.Node): ts.Symbol | undefined;

636

637

/**

638

* Gets the TypeScript type at the given ESTree node location

639

* @param node - ESTree node to get type for

640

* @returns TypeScript type information

641

*/

642

getTypeAtLocation(node: TSESTree.Node): ts.Type;

643

}

644

```

645

646

**Usage Examples:**

647

648

```typescript

649

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

650

651

// Using AST node types

652

function processNode(node: TSESTree.Node): void {

653

switch (node.type) {

654

case TSESTree.AST_NODE_TYPES.FunctionDeclaration:

655

// node is now typed as TSESTree.FunctionDeclaration

656

console.log('Function name:', node.id?.name);

657

break;

658

case TSESTree.AST_NODE_TYPES.CallExpression:

659

// node is now typed as TSESTree.CallExpression

660

console.log('Call expression with', node.arguments.length, 'arguments');

661

break;

662

}

663

}

664

665

// Using parser services in a rule

666

const rule: TSESLint.RuleModule<'error', []> = {

667

meta: {

668

type: 'problem',

669

messages: { error: 'Type error: {{message}}' },

670

schema: []

671

},

672

create(context) {

673

const services = ESLintUtils.getParserServices(context);

674

const checker = services.program?.getTypeChecker();

675

676

return {

677

CallExpression(node: TSESTree.CallExpression) {

678

if (checker && services.hasFullTypeInformation) {

679

const tsNode = services.esTreeNodeToTSNodeMap.get(node);

680

if (tsNode) {

681

const type = checker.getTypeAtLocation(tsNode);

682

const typeString = checker.typeToString(type);

683

684

context.report({

685

node,

686

messageId: 'error',

687

data: { message: `Called expression has type: ${typeString}` }

688

});

689

}

690

}

691

}

692

};

693

}

694

};

695

696

// Working with tokens

697

function analyzeTokens(sourceCode: TSESLint.SourceCode): void {

698

const tokens = sourceCode.getTokens();

699

700

tokens.forEach(token => {

701

switch (token.type) {

702

case TSESTree.AST_TOKEN_TYPES.Keyword:

703

console.log('Found keyword:', token.value);

704

break;

705

case TSESTree.AST_TOKEN_TYPES.Identifier:

706

console.log('Found identifier:', token.value);

707

break;

708

case TSESTree.AST_TOKEN_TYPES.Punctuator:

709

console.log('Found punctuator:', token.value);

710

break;

711

}

712

});

713

}

714

715

// Type-safe node checking

716

function isFunctionLike(node: TSESTree.Node): node is TSESTree.FunctionLike {

717

return node.type === TSESTree.AST_NODE_TYPES.FunctionDeclaration ||

718

node.type === TSESTree.AST_NODE_TYPES.FunctionExpression ||

719

node.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression ||

720

node.type === TSESTree.AST_NODE_TYPES.TSEmptyBodyFunctionExpression ||

721

node.type === TSESTree.AST_NODE_TYPES.TSDeclareFunction;

722

}

723

724

// TypeScript-specific node handling

725

function processTypeAnnotation(node: TSESTree.TSTypeAnnotation): void {

726

const typeNode = node.typeAnnotation;

727

728

switch (typeNode.type) {

729

case TSESTree.AST_NODE_TYPES.TSStringKeyword:

730

console.log('String type annotation');

731

break;

732

case TSESTree.AST_NODE_TYPES.TSNumberKeyword:

733

console.log('Number type annotation');

734

break;

735

case TSESTree.AST_NODE_TYPES.TSUnionType:

736

console.log('Union type with', typeNode.types.length, 'members');

737

break;

738

}

739

}

740

```

741

742

## Node Interface Examples

743

744

Key TypeScript ESTree node interfaces demonstrating the structure:

745

746

```typescript { .api }

747

// Core JavaScript nodes

748

interface ArrayExpression extends BaseNode {

749

type: AST_NODE_TYPES.ArrayExpression;

750

elements: (Expression | SpreadElement | null)[];

751

}

752

753

interface ObjectExpression extends BaseNode {

754

type: AST_NODE_TYPES.ObjectExpression;

755

properties: (Property | SpreadElement)[];

756

}

757

758

interface Property extends BaseNode {

759

type: AST_NODE_TYPES.Property;

760

key: PropertyName;

761

value: Expression | Pattern;

762

kind: 'init' | 'get' | 'set';

763

method: boolean;

764

shorthand: boolean;

765

computed: boolean;

766

}

767

768

interface MethodDefinition extends BaseNode {

769

type: AST_NODE_TYPES.MethodDefinition;

770

key: PropertyName;

771

value: FunctionExpression | TSEmptyBodyFunctionExpression;

772

kind: 'constructor' | 'method' | 'get' | 'set';

773

computed: boolean;

774

static: boolean;

775

override?: boolean;

776

optional?: boolean;

777

accessibility?: 'public' | 'protected' | 'private';

778

decorators?: Decorator[];

779

}

780

781

// TypeScript-specific nodes

782

interface TSInterfaceBody extends BaseNode {

783

type: AST_NODE_TYPES.TSInterfaceBody;

784

body: TypeElement[];

785

}

786

787

interface TSPropertySignature extends BaseNode {

788

type: AST_NODE_TYPES.TSPropertySignature;

789

key: PropertyName;

790

typeAnnotation?: TSTypeAnnotation;

791

optional?: boolean;

792

computed?: boolean;

793

readonly?: boolean;

794

}

795

796

interface TSMethodSignature extends BaseNode {

797

type: AST_NODE_TYPES.TSMethodSignature;

798

key: PropertyName;

799

params: Parameter[];

800

returnType?: TSTypeAnnotation;

801

computed?: boolean;

802

optional?: boolean;

803

kind: 'method' | 'get' | 'set';

804

typeParameters?: TSTypeParameterDeclaration;

805

}

806

807

interface TSTypeReference extends BaseNode {

808

type: AST_NODE_TYPES.TSTypeReference;

809

typeName: EntityName;

810

typeParameters?: TSTypeParameterInstantiation;

811

}

812

813

interface TSUnionType extends BaseNode {

814

type: AST_NODE_TYPES.TSUnionType;

815

types: TypeNode[];

816

}

817

818

interface TSIntersectionType extends BaseNode {

819

type: AST_NODE_TYPES.TSIntersectionType;

820

types: TypeNode[];

821

}

822

```