What is @typescript-eslint/typescript-estree?
The @typescript-eslint/typescript-estree package is a parser that converts TypeScript source code into an ESTree-compatible form. It is primarily used in the context of ESLint to enable linting of TypeScript code by converting TypeScript syntax into a format that ESLint can understand and work with.
What are @typescript-eslint/typescript-estree's main functionalities?
Parsing TypeScript code to ESTree
This feature allows you to parse TypeScript code and get an Abstract Syntax Tree (AST) that is compatible with ESTree. This is useful for tools that need to analyze or manipulate the syntax of TypeScript code.
const tsEStree = require('@typescript-eslint/typescript-estree');
const code = 'let x: number = 1;';
const ast = tsEStree.parse(code, { jsx: false });
console.log(ast);
Parsing TypeScript code with JSX
This feature is similar to the previous one but includes support for JSX syntax, which is commonly used in React applications. It allows the parser to correctly interpret JSX elements within TypeScript code.
const tsEStree = require('@typescript-eslint/typescript-estree');
const code = '<div>Hello, TypeScript!</div>';
const ast = tsEStree.parse(code, { jsx: true });
console.log(ast);
Parsing a file
This feature allows you to parse the contents of a TypeScript file by reading the file and then parsing the code. It is useful when you want to analyze or lint a file directly.
const tsEStree = require('@typescript-eslint/typescript-estree');
const fs = require('fs');
const filePath = './example.ts';
const code = fs.readFileSync(filePath, 'utf8');
const ast = tsEStree.parse(code, { filePath });
console.log(ast);
Other packages similar to @typescript-eslint/typescript-estree
typescript-eslint-parser
This package was the predecessor to @typescript-eslint/typescript-estree and has been deprecated in favor of the newer package. It provided similar functionality in terms of parsing TypeScript code for ESLint.
babel-eslint
babel-eslint is a parser that allows ESLint to run on source code that is transpiled with Babel. While it is not TypeScript-specific, it can be used with Babel's TypeScript preset to parse TypeScript code.
espree
Espree is the default parser for ESLint and is built on top of Acorn. It is designed to parse ECMAScript (JavaScript) code. While it does not natively support TypeScript, it serves a similar purpose for JavaScript code as @typescript-eslint/typescript-estree does for TypeScript.
8.0.1 (2024-08-05)
🩹 Fixes
- eslint-plugin: [no-unused-vars] ignore imports used only as types (#9694)
❤️ Thank You
You can read about our versioning strategy and releases on our website.
👉 See Announcing typescript-eslint v8 for an upgrade guide and the full list of changes.
⚠️ Breaking Changes
- typescript-estree: split TSMappedType typeParameter into constraint and key (#7065)
- parser: always enable comment, loc, range, tokens (#8617)
- eslint-plugin: [prefer-nullish-coalescing] change ignoreConditionalTests default to true (#8872)
- typescript-estree: enable dot globs for project by default (#8818)
- eslint-plugin: deprecate no-loss-of-precision extension rule (#8832)
- eslint-plugin: remove formatting/layout rules (#8833)
- typescript-estree: remove slow deprecated and isolated programs (#8834)
- typescript-estree: add TSEnumBody node for TSEnumDeclaration body (#8920)
- typescript-estree: rename automaticSingleRunInference to disallowAutomaticSingleRunInference (#8922)
- ast-spec: remove deprecated type params (#8933)
- type-utils: remove IsNullableTypeOptions interface (#8934)
- eslint-plugin: [no-unused-vars] align catch behavior to ESLint 9 (#8971)
- utils: swap LegacyESLint out for FlatESLint as ESLint export (#8972)
- eslint-plugin: split no-empty-object-type out from ban-types and no-empty-interfaces (#8977)
- utils: allow specifying additional rule meta.docs in RuleCreator (#9025)
- eslint-plugin: apply initial config changes for v8 (#9079)
- eslint-plugin: replace ban-types with no-restricted-types, no-unsafe-function-type, no-wrapper-object-types (#9102)
- typescript-estree: remove EXPERIMENTAL_useSourceOfProjectReferenceRedirect (#9104)
- eslint-plugin: remove no-useless-template-literals (#9207)
- type-utils: remove getTokenAtPosition (#9444)
- eslint-plugin: [no-floating-promises] disable checkThenables by default for v8 (#9559)
- rule-tester: switched to flat config (#9603)
🚀 Features
- stricter parent types for the AST (#9560)
- speed up non-type-aware linting with project service (#8322)
- v8 integration branch (#9165)
- eslint-plugin: remove deprecated no-throw-literal rule (#9092)
- eslint-plugin: [no-floating-promises] add 'allowForKnownSafeCalls' option (#9234)
- eslint-plugin: [no-unused-vars] add
reportUnusedIgnorePattern
option (#9324) - eslint-plugin: [no-unused-vars] support
ignoreClassWithStaticInitBlock
(#9325) - eslint-plugin: [no-unused-vars] handle comma operator for assignments, treat for-of the same as for-in (#9326)
- eslint-plugin: [no-unused-vars] report if var used only in typeof (#9330)
- eslint-plugin: [return-await] add return-await to strict-type-checked preset (#9604)
- eslint-plugin: [no-unnecessary-type-parameters] promote to strict (#9662)
- rule-tester: support multipass fixes (#8883)
- type-utils: support intersection types in TypeOrValueSpecifier (#9633)
- typescript-estree: stabilize EXPERIMENTAL_useProjectService as projectService (#9084)
- typescript-estree: also remove projectService in withoutProjectParserOptions (#9287)
- typescript-estree: exposes ProjectService logs through the plugin (#9337)
- utils: add Linter configType constructor option (#8999)
- utils: remove deprecated context helpers (#9000)
🩹 Fixes
- correct eslint-plugin's peerDependency on parser@8 (#9089)
- bring back in allowdefaultprojectforfiles rename (7dfceeeea)
- disable
projectService
in disabled-type-checked
shared config (#9460) - eslint-plugin: include alpha pre-releases in parser peer dependency (#9099)
- eslint-plugin: correct rules.d.ts types to not rely on non-existent imports (#9339)
- eslint-plugin: remove duplicate import
RuleModuleWithMetaDocs
(#9465) - eslint-plugin: [no-unnecessary-template-expression] do not render escaped strings in autofixes (#8688)
- eslint-plugin: [no-unused-vars] incorporate upstream changes around caught errors report messages (#9532)
- eslint-plugin: [no-misused-promises] perf: avoid getting types of variables/functions if the annotated type is obviously not a function (#9656)
- rule-tester: set configType to eslintrc in Linter options (#9178)
- rule-tester: re-apply updates from main (#9180)
- rule-tester: provide Linter a cwd in its constructor (#9678)
- type-utils: also check declared modules for package names in TypeOrValueSpecifier (#9500)
- types: allow ProjectServiceOptions for projectService (#9318)
- typescript-estree: pass extraFileExtensions to projectService (#9051)
- typescript-estree: only run projectService setHostConfiguration when needed (#9336)
- typescript-estree: specific error for parserOptions.project not including a file (#9584)
- typescript-estree: adds support for project services using extended config files (#9306)
- typescript-estree: factor tsconfigRootDir into allowDefaultProject (#9675)
❤️ Thank You
- Abraham Guo
- Alfred Ringstad @alfredringstad
- auvred @auvred
- Brad Zacher @bradzacher
- Christopher Aubut @higherorderfunctor
- Collin Bachman @bachmacintosh
- James Henry @JamesHenry
- Josh Goldberg
- Josh Goldberg ✨
- Kirk Waiblinger @kirkwaiblinger
- StyleShit @StyleShit
- Victor Lin @yepitschunked
- Yukihiro Hasegawa @y-hsgw
You can read about our versioning strategy and releases on our website.