Skip to main content

Overview

@typescript-eslint/eslint-plugin includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below.

tip

Instead of enabling rules one by one, we recommend using one of our pre-defined configs to enable a large set of recommended rules.

Rules​

The rules are listed in alphabetical order. You can optionally filter them based on these categories:

Config Group (βš™οΈ)
Metadata

(These categories are explained in more detail below.)

Rule
βš™οΈ
πŸ”§
πŸ’­
🧱
πŸ’€

Require that function overload signatures be consecutive
🎨

Require consistently using either T[] or Array<T> for arrays
πŸŽ¨πŸ”§

Disallow awaiting a value that is not a Thenable
βœ…πŸ’‘πŸ’­

Disallow @ts-<directive> comments or require descriptions after directives
βœ…πŸ’‘

Disallow // tslint:<rule-flag> comments
πŸŽ¨πŸ”§

Enforce that literals on classes are exposed in a consistent style
πŸŽ¨πŸ’‘

Enforce that class methods utilize this
🧱

Enforce specifying generic type arguments on type annotation or constructor name of a constructor call
πŸŽ¨πŸ”§

Require or disallow the Record type
πŸŽ¨πŸ”§
πŸ’‘

Require return statements to either always or never specify values
πŸ’­πŸ§±

Enforce consistent usage of type assertions
πŸŽ¨πŸ”§
πŸ’‘

Enforce type definitions to consistently use either interface or type
πŸŽ¨πŸ”§

Enforce consistent usage of type exports
πŸ”§πŸ’­

Enforce consistent usage of type imports
πŸ”§

Enforce default parameters to be last
🧱

Enforce dot notation whenever possible
πŸŽ¨πŸ”§πŸ’­πŸ§±

Require explicit return types on functions and class methods

Require explicit accessibility modifiers on class properties and methods
πŸ”§
πŸ’‘

Require explicit return and argument types on exported functions' and classes' public class methods

Require or disallow initialization in variable declarations
🧱

Enforce a maximum number of parameters in function definitions
🧱

Require a consistent member declaration order

Enforce using a particular method signature syntax
πŸ”§

Enforce naming conventions for everything across a codebase
πŸ’­

Disallow generic Array constructors
βœ…πŸ”§πŸ§±

Disallow using the delete operator on array values
βœ…πŸ’‘πŸ’­

Require .toString() and .toLocaleString() to only be called on objects which provide useful information when stringified
βœ…πŸ’­

Disallow non-null assertion in locations that may be confusing
πŸŽ¨πŸ’‘

Require expressions of type void to appear in statement position
πŸ”’πŸ”§
πŸ’‘
πŸ’­

Disallow using code marked as @deprecated
πŸ”’πŸ’­

Disallow duplicate class members
🧱

Disallow duplicate enum member values
βœ…

Disallow duplicate constituents of union or intersection types
βœ…πŸ”§πŸ’­

Disallow using the delete operator on computed key expressions
πŸ”’πŸ”§

Disallow empty functions
🎨🧱

Disallow the declaration of empty interfaces
πŸ”§
πŸ’‘
πŸ’€

Disallow accidentally using the "empty object" type
βœ…πŸ’‘

Disallow the any type
βœ…πŸ”§
πŸ’‘

Disallow extra non-null assertions
βœ…πŸ”§

Disallow classes used as namespaces
πŸ”’

Require Promise-like statements to be handled appropriately
βœ…πŸ’‘πŸ’­

Disallow iterating over an array with a for-in loop
βœ…πŸ’­

Disallow the use of eval()-like functions
βœ…πŸ’­πŸ§±

Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
πŸ”§

Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean
πŸŽ¨πŸ”§

Disallow this keywords outside of classes or class-like objects
🧱

Disallow void type outside of generic or return types
πŸ”’

Disallow function declarations that contain unsafe references inside loop statements
🧱

Disallow literal numbers that lose precision
πŸ§±πŸ’€

Disallow magic numbers
🧱

Disallow the void operator except when used to discard a value
πŸ”’πŸ”§
πŸ’‘
πŸ’­

Enforce valid definition of new and constructor
βœ…

Disallow Promises in places not designed to handle them
βœ…πŸ’­

Disallow using the spread operator when it might cause unexpected behavior
πŸ”’πŸ’‘πŸ’­

Disallow enums from having both number and string members
πŸ”’πŸ’­

Disallow TypeScript namespaces
βœ…

Disallow non-null assertions in the left operand of a nullish coalescing operator
πŸ”’πŸ’‘

Disallow non-null assertions after an optional chain expression
βœ…πŸ’‘

Disallow non-null assertions using the ! postfix operator
πŸ”’πŸ’‘

Disallow variable redeclaration
🧱

Disallow members of unions and intersections that do nothing or override type information
βœ…πŸ’­

Disallow invocation of require()
βœ…

Disallow specified modules when loaded by import
🧱

Disallow certain types
πŸ”§
πŸ’‘

Disallow variable declarations from shadowing variables declared in the outer scope
🧱

Disallow aliasing this
βœ…

Disallow type aliases
πŸ’€

Disallow unnecessary equality comparisons against boolean literals
πŸ”’πŸ”§πŸ’­

Disallow conditionals where the type is always truthy or always falsy
πŸ”’πŸ’‘πŸ’­

Disallow unnecessary assignment of constructor property parameter

Disallow unnecessary namespace qualifiers
πŸ”§πŸ’­

Disallow unnecessary template expressions
πŸ”’πŸ”§πŸ’­

Disallow type arguments that are equal to the default
πŸ”’πŸ”§πŸ’­

Disallow type assertions that do not change the type of an expression
βœ…πŸ”§πŸ’­

Disallow unnecessary constraints on generic types
βœ…πŸ’‘

Disallow conversion idioms when they do not change the type or value of the expression
πŸ”’πŸ’‘πŸ’­

Disallow type parameters that aren't used multiple times
πŸ”’πŸ’‘πŸ’­

Disallow calling a function with a value with type any
βœ…πŸ’­

Disallow assigning a value with type any to variables and properties
βœ…πŸ’­

Disallow calling a value with type any
βœ…πŸ’­

Disallow unsafe declaration merging
βœ…

Disallow comparing an enum value with a non-enum value
βœ…πŸ’‘πŸ’­

Disallow using the unsafe built-in Function type
βœ…

Disallow member access on a value with type any
βœ…πŸ’­

Disallow returning a value with type any from a function
βœ…πŸ’­

Disallow type assertions that narrow a type
πŸ’­

Require unary negation to take a number
βœ…πŸ’­

Disallow unused expressions
βœ…πŸ§±

Disallow unused variables
βœ…πŸ§±

Disallow the use of variables before they are defined
🧱

Disallow unnecessary constructors
πŸ”’πŸ’‘πŸ§±

Disallow empty exports that don't change anything in a module file
πŸ”§

Disallow require statements except in import statements
πŸ’€

Disallow using confusing built-in primitive class wrappers
βœ…πŸ”§

Enforce non-null assertions over explicit type assertions
πŸŽ¨πŸ”§πŸ’­

Disallow throwing non-Error values as exceptions
βœ…πŸ’­πŸ§±

Require or disallow parameter properties in class constructors

Enforce the use of as const over literal type
βœ…πŸ”§
πŸ’‘

Require destructuring from arrays and/or objects
πŸ”§πŸ’­πŸ§±

Require each enum member value to be explicitly initialized
πŸ’‘

Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result
πŸŽ¨πŸ’‘πŸ’­

Enforce the use of for-of loop over the standard for loop where possible
🎨

Enforce using function types instead of interfaces with call signatures
πŸŽ¨πŸ”§

Enforce includes method over indexOf method
πŸŽ¨πŸ”§πŸ’­

Require all enum members to be literal values
πŸ”’

Require using namespace keyword over module keyword to declare custom TypeScript modules
βœ…πŸ”§

Enforce using the nullish coalescing operator instead of logical assignments or chaining
πŸŽ¨πŸ’‘πŸ’­

Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects
πŸŽ¨πŸ”§
πŸ’‘
πŸ’­

Require using Error objects as Promise rejection reasons
βœ…πŸ’­πŸ§±

Require private members to be marked as readonly if they're never modified outside of the constructor
πŸ”§πŸ’­

Require function parameters to be typed as readonly to prevent accidental mutation of inputs
πŸ’­

Enforce using type parameter when calling Array#reduce instead of using a type assertion
πŸ”’πŸ”§πŸ’­

Enforce RegExp#exec over String#match if no global flag is provided
πŸŽ¨πŸ”§πŸ’­

Enforce that this is used when only this type is returned
πŸ”’πŸ”§πŸ’­

Enforce using String#startsWith and String#endsWith over other equivalent methods of checking substrings
πŸŽ¨πŸ”§πŸ’­

Enforce using @ts-expect-error over @ts-ignore
πŸ”§πŸ’€

Require any function or method that returns a Promise to be marked async
πŸ”§πŸ’­

Enforce that get() types should be assignable to their equivalent set() type
πŸ”’πŸ’­

Require Array#sort and Array#toSorted calls to always provide a compareFunction
πŸ’­

Disallow async functions which do not return promises and have no await expression
βœ…πŸ’‘πŸ’­πŸ§±

Require both operands of addition to be the same type and be bigint, number, or string
βœ…πŸ’­

Enforce template literal expressions to be of string type
βœ…πŸ’­

Enforce consistent awaiting of returned promises
πŸ”’πŸ”§
πŸ’‘
πŸ’­

Enforce constituents of a type union/intersection to be sorted alphabetically
πŸ”§
πŸ’‘
πŸ’€

Disallow certain types in boolean expressions
πŸ’‘πŸ’­

Require switch-case statements to be exhaustive
πŸ’‘πŸ’­

Disallow certain triple slash directives in favor of ES6-style import declarations
βœ…

Require type annotations in certain places
πŸ’€

Enforce unbound methods are called with their expected scope
βœ…πŸ’­

Disallow two overloads that could be unified into one with a union or an optional/rest parameter
πŸ”’

Enforce typing arguments in Promise rejection callbacks as unknown
πŸ”’πŸ’‘πŸ’­

Filtering​

Config Group (βš™οΈ)​

"Config Group" refers to the pre-defined config that includes the rule. Extending from a configuration preset allow for enabling a large set of recommended rules all at once.

Metadata​

  • πŸ”§ fixable refers to whether the rule contains an ESLint --fix auto-fixer.
  • πŸ’‘ has suggestions refers to whether the rule contains an ESLint suggestion fixer.
    • Sometimes, it is not safe to automatically fix the code with an auto-fixer. But in these cases, we often have a good guess of what the correct fix should be, and we can provide it as a suggestion to the developer.
  • πŸ’­ requires type information refers to whether the rule requires typed linting.
  • 🧱 extension rule means that the rule is an extension of an core ESLint rule (see Extension Rules).
  • πŸ’€ deprecated rule means that the rule should no longer be used and will be removed from the plugin in a future version.

Extension Rules​

Some core ESLint rules do not support TypeScript syntax: either they crash, ignore the syntax, or falsely report against it. In these cases, we create what we call an "extension rule": a rule within our plugin that has the same functionality, but also supports TypeScript.

Extension rules generally completely replace the base rule from ESLint core. If the base rule is enabled in a config you extend from, you'll need to disable the base rule:

module.exports = {
extends: ['eslint:recommended'],
rules: {
// Note: you must disable the base rule as it can report incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
},
};

Search for 🧱 extension rules in this page to see all extension rules.

Frozen Rules​

When rules are feature complete, they are marked as frozen (indicated with ❄️ in the documentation). This applies to standalone rules that are complete, as well as extension rules whose underlying core ESLint rules are frozen. After that point, we expect users to use disable comments when they find an edge case that isn’t covered.

When a rule is frozen, it means:

  • Bug fixes: We will still fix confirmed bugs.
  • New ECMAScript features: We will ensure compatibility with new ECMAScript features, meaning the rule will not break on new syntax.
  • TypeScript support: We will ensure compatibility with TypeScript syntax, meaning the rule will not break on TypeScript syntax and violations are appropriate for TypeScript.
  • New options: We will not add any new options unless an option is the only way to fix a bug or support a newly-added ECMAScript feature.

If you find that a frozen rule would work better for you with a change, we recommend copying the rule source code and modifying it to fit your needs.