This page describes the top-level packages exported by the typescript-eslint monorepo.
Each of these are published as npm packages under the
@typescript-eslint/eslint-plugin is the core ESLint plugin used by consumers to load in custom rules and rule configurations lists from typescript-eslint.
Those rules rely on ESLint using the
@typescript-eslint/parser package described below, and are generally built using the other packages on this page.
@typescript-eslint/parser takes in ESLint configuration settings, reads in TypeScript source text, and produces an ESTree AST.
This is necessary because TypeScript produces a different, incompatible AST format to the one that ESLint requires to work.
: number type annotation:
let x: number = 1;
ESLint's native Espree parser would raise an error attempting to parse it.
Additionally, because TypeScript is developed separately and with different goals from ESLint, ESTree, and Espree, its AST also represents nodes differently in many cases. TS's AST is optimized for its use case of parsing incomplete code and typechecking. ESTree is unoptimized and intended for "general purpose" use-cases of traversing the AST.
See more on configuring custom parsers with ESLint on ESLint's User Guide > Configuring > Plugins.
You can select
@typescript-eslint/parser on astexplorer.net's top-middle ⚙ dropdown that defaults to Acorn.
@typescript-eslint/typescript-estree is used by
@typescript-eslint/parser to take TypeScript source code and produce the equivalent ESTree AST.
It works by:
- Invoking the TypeScript compiler on the given source code in order to produce a TypeScript AST
- Converting that TypeScript AST into an ESTree AST
@typescript-eslint/typescript-estreehas a very specific purpose, it is reusable for tools with similar requirements to ESLint. It is therefore also used to power the amazing opinionated code formatter Prettier's TypeScript support.
A "scope analyser" traverses an AST and builds a model of how variables (and in our case, types) are defined and consumed by the source code. This form of static analysis allows you to understand and trace variables throughout the program, allowing you to access powerful information about a program without needing to drop into the much, much heavier type information.
@typescript-eslint/experimental-utils contains public utilities for writing custom rules and plugins in TypeScript.
Rules declared in
@typescript-eslint/eslint-plugin are created using its utility functions.
Any custom rules you write generally will be as well.
@typescript-eslint/eslint-plugin-tslint is a separate ESLint plugin that allows running TSLint rules within ESLint to help you migrate from TSLint to ESLint.
TSLint is deprecated. It is in your best interest to migrate off it entirely. See Linting > TSLint.