or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-node-types.mdindex.mdparser-configuration.mdtoken-types.mdtypescript-estree.mdtypescript-libraries.md

index.mddocs/

0

# @typescript-eslint/types

1

2

@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.

3

4

## Package Information

5

6

- **Package Name**: @typescript-eslint/types

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install @typescript-eslint/types`

10

11

## Core Imports

12

13

```typescript

14

import { AST_NODE_TYPES, AST_TOKEN_TYPES, ParserOptions, TSESTree, Lib } from "@typescript-eslint/types";

15

```

16

17

For CommonJS:

18

19

```javascript

20

const { AST_NODE_TYPES, AST_TOKEN_TYPES, ParserOptions, TSESTree, Lib } = require("@typescript-eslint/types");

21

```

22

23

## Basic Usage

24

25

```typescript

26

import { AST_NODE_TYPES, ParserOptions, TSESTree } from "@typescript-eslint/types";

27

28

// Check AST node types

29

if (node.type === AST_NODE_TYPES.FunctionDeclaration) {

30

// TypeScript now knows this is a function declaration node

31

console.log(node.id?.name);

32

}

33

34

// Configure parser options

35

const parserOptions: ParserOptions = {

36

ecmaVersion: 2022,

37

sourceType: "module",

38

project: "./tsconfig.json",

39

lib: ["es2022", "dom"]

40

};

41

42

// Work with strongly-typed AST nodes

43

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

44

switch (node.type) {

45

case AST_NODE_TYPES.VariableDeclaration:

46

// TypeScript provides full type safety

47

node.declarations.forEach(declarator => {

48

if (declarator.id.type === AST_NODE_TYPES.Identifier) {

49

console.log(`Variable: ${declarator.id.name}`);

50

}

51

});

52

break;

53

}

54

}

55

```

56

57

## Architecture

58

59

@typescript-eslint/types is built around several key components:

60

61

- **AST Node Types**: Enum constants for all JavaScript and TypeScript AST node types

62

- **Token Types**: Enum constants for lexical token classification

63

- **Parser Configuration**: Comprehensive interfaces for configuring the TypeScript parser

64

- **Type System**: Complete TypeScript definitions for all AST node structures

65

- **Parent Relationships**: Augmented type definitions that include parent node references

66

67

## Capabilities

68

69

### AST Node Type Constants

70

71

Comprehensive enumeration of all AST node types for JavaScript and TypeScript, enabling type-safe node identification and processing.

72

73

```typescript { .api }

74

enum AST_NODE_TYPES {

75

// Standard JavaScript nodes

76

Program = 'Program',

77

Identifier = 'Identifier',

78

Literal = 'Literal',

79

FunctionDeclaration = 'FunctionDeclaration',

80

// ... 172 total node types

81

82

// TypeScript-specific nodes

83

TSInterfaceDeclaration = 'TSInterfaceDeclaration',

84

TSTypeAnnotation = 'TSTypeAnnotation',

85

TSAsExpression = 'TSAsExpression',

86

// ... and many more

87

}

88

```

89

90

[AST Node Types](./ast-node-types.md)

91

92

### Token Type Constants

93

94

Enumeration of lexical token types for parsing and syntax highlighting.

95

96

```typescript { .api }

97

enum AST_TOKEN_TYPES {

98

Boolean = 'Boolean',

99

Identifier = 'Identifier',

100

Keyword = 'Keyword',

101

Null = 'Null',

102

Numeric = 'Numeric',

103

Punctuator = 'Punctuator',

104

RegularExpression = 'RegularExpression',

105

String = 'String',

106

Template = 'Template',

107

Block = 'Block', // Block comment

108

Line = 'Line', // Line comment

109

// ... 18 total token types

110

}

111

```

112

113

[Token Types](./token-types.md)

114

115

### Parser Configuration

116

117

Comprehensive configuration interfaces for the TypeScript parser, including ECMAScript version settings, project configuration, and TypeScript-specific options.

118

119

```typescript { .api }

120

interface ParserOptions {

121

// ECMAScript configuration

122

ecmaVersion?: EcmaVersion;

123

sourceType?: SourceType;

124

125

// TypeScript project configuration

126

project?: boolean | string | string[] | null;

127

projectService?: boolean | ProjectServiceOptions;

128

tsconfigRootDir?: string;

129

130

// Parser features

131

jsxPragma?: string | null;

132

jsxFragmentName?: string | null;

133

lib?: Lib[];

134

135

// Debug and optimization

136

debugLevel?: DebugLevel;

137

errorOnUnknownASTType?: boolean;

138

139

// ... 25+ additional options

140

}

141

```

142

143

[Parser Configuration](./parser-configuration.md)

144

145

### TypeScript Library Targets

146

147

Union type defining all available TypeScript library targets for compilation and type checking.

148

149

```typescript { .api }

150

type Lib =

151

| 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018'

152

| 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024'

153

| 'esnext' | 'dom' | 'webworker' | 'scripthost'

154

| 'decorators' | 'decorators.legacy'

155

// ... 114 total library targets

156

```

157

158

[TypeScript Libraries](./typescript-libraries.md)

159

160

### TypeScript ESTree Types

161

162

Complete type definitions for all AST node structures with parent relationship augmentations, providing strongly-typed access to the entire syntax tree.

163

164

```typescript { .api }

165

declare namespace TSESTree {

166

interface NodeOrTokenData {

167

type: string;

168

loc: SourceLocation;

169

range: Range;

170

}

171

172

interface BaseNode extends NodeOrTokenData {

173

type: AST_NODE_TYPES;

174

parent: Node; // Added by @typescript-eslint/types package

175

}

176

177

interface Program extends NodeOrTokenData {

178

type: AST_NODE_TYPES.Program;

179

body: ProgramStatement[];

180

comments: Comment[] | undefined;

181

sourceType: 'module' | 'script';

182

tokens: Token[] | undefined;

183

parent?: never; // Program has no parent

184

}

185

186

interface FunctionDeclaration extends BaseNode {

187

type: AST_NODE_TYPES.FunctionDeclaration;

188

id: Identifier | null;

189

params: Parameter[];

190

body: BlockStatement;

191

// ... complete interface definitions

192

}

193

194

// ... interfaces for all 172 node types

195

}

196

```

197

198

[TypeScript ESTree](./typescript-estree.md)