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. See Configs for how to enable recommended rules using configs.

Supported Rules​

Key: βœ… = recommended, πŸ”’ = strict, πŸ”§ = fixable, πŸ’­ = requires type information

NameDescriptionβœ…πŸ”’πŸ”§πŸ’­
@typescript-eslint/adjacent-overload-signaturesRequire that member overloads be consecutiveβœ…
@typescript-eslint/array-typeRequires using either T[] or Array<T> for arraysπŸ”’πŸ”§
@typescript-eslint/await-thenableDisallows awaiting a value that is not a Thenableβœ…πŸ’­
@typescript-eslint/ban-ts-commentBans @ts-<directive> comments from being used or requires descriptions after directiveβœ…
@typescript-eslint/ban-tslint-commentBans // tslint:<rule-flag> comments from being usedπŸ”’πŸ”§
@typescript-eslint/ban-typesBans specific types from being usedβœ…πŸ”§
@typescript-eslint/class-literal-property-styleEnsures that literals on classes are exposed in a consistent styleπŸ”’πŸ”§
@typescript-eslint/consistent-indexed-object-styleEnforce or disallow the use of the record typeπŸ”’πŸ”§
@typescript-eslint/consistent-type-assertionsEnforces consistent usage of type assertionsπŸ”’
@typescript-eslint/consistent-type-definitionsConsistent with type definition either interface or typeπŸ”’πŸ”§
@typescript-eslint/consistent-type-exportsEnforces consistent usage of type exportsπŸ”§πŸ’­
@typescript-eslint/consistent-type-importsEnforces consistent usage of type importsπŸ”§
@typescript-eslint/explicit-function-return-typeRequire explicit return types on functions and class methods
@typescript-eslint/explicit-member-accessibilityRequire explicit accessibility modifiers on class properties and methodsπŸ”§
@typescript-eslint/explicit-module-boundary-typesRequire explicit return and argument types on exported functions' and classes' public class methods
@typescript-eslint/member-delimiter-styleRequire a specific member delimiter style for interfaces and type literalsπŸ”§
@typescript-eslint/member-orderingRequire a consistent member declaration order
@typescript-eslint/method-signature-styleEnforces using a particular method signature syntaxπŸ”§
@typescript-eslint/naming-conventionEnforces naming conventions for everything across a codebaseπŸ’­
@typescript-eslint/no-base-to-stringRequires that .toString() is only called on objects which provide useful information when stringifiedπŸ”’πŸ’­
@typescript-eslint/no-confusing-non-null-assertionDisallow non-null assertion in locations that may be confusingπŸ”’πŸ”§
@typescript-eslint/no-confusing-void-expressionRequires expressions of type void to appear in statement positionπŸ”§πŸ’­
@typescript-eslint/no-duplicate-enum-valuesDisallow duplicate enum member valuesπŸ”’
@typescript-eslint/no-dynamic-deleteDisallow the delete operator with computed key expressionsπŸ”’πŸ”§
@typescript-eslint/no-empty-interfaceDisallow the declaration of empty interfacesβœ…πŸ”§
@typescript-eslint/no-explicit-anyDisallow usage of the any typeβœ…πŸ”§
@typescript-eslint/no-extra-non-null-assertionDisallow extra non-null assertionβœ…πŸ”§
@typescript-eslint/no-extraneous-classForbids the use of classes as namespacesπŸ”’
@typescript-eslint/no-floating-promisesRequires Promise-like statements to be handled appropriatelyβœ…πŸ’­
@typescript-eslint/no-for-in-arrayDisallow iterating over an array with a for-in loopβœ…πŸ’­
@typescript-eslint/no-inferrable-typesDisallows explicit type declarations for variables or parameters initialized to a number, string, or booleanβœ…πŸ”§
@typescript-eslint/no-invalid-void-typeDisallows usage of void type outside of generic or return typesπŸ”’
@typescript-eslint/no-meaningless-void-operatorDisallow the void operator except when used to discard a valueπŸ”’πŸ”§πŸ’­
@typescript-eslint/no-misused-newEnforce valid definition of new and constructorβœ…
@typescript-eslint/no-misused-promisesAvoid using Promises in places not designed to handle themβœ…πŸ’­
@typescript-eslint/no-namespaceDisallow the use of custom TypeScript modules and namespacesβœ…
@typescript-eslint/no-non-null-asserted-nullish-coalescingDisallows using a non-null assertion in the left operand of the nullish coalescing operatorπŸ”’
@typescript-eslint/no-non-null-asserted-optional-chainDisallows using a non-null assertion after an optional chain expressionβœ…
@typescript-eslint/no-non-null-assertionDisallows non-null assertions using the ! postfix operatorβœ…
@typescript-eslint/no-parameter-propertiesDisallow the use of parameter properties in class constructors
@typescript-eslint/no-redundant-type-constituentsDisallow members of unions and intersections that do nothing or override type informationπŸ’­
@typescript-eslint/no-require-importsDisallows invocation of require()
@typescript-eslint/no-this-aliasDisallow aliasing thisβœ…
@typescript-eslint/no-type-aliasDisallow the use of type aliases
@typescript-eslint/no-unnecessary-boolean-literal-compareFlags unnecessary equality comparisons against boolean literalsπŸ”’πŸ”§πŸ’­
@typescript-eslint/no-unnecessary-conditionPrevents conditionals where the type is always truthy or always falsyπŸ”’πŸ”§πŸ’­
@typescript-eslint/no-unnecessary-qualifierWarns when a namespace qualifier is unnecessaryπŸ”§πŸ’­
@typescript-eslint/no-unnecessary-type-argumentsEnforces that type arguments will not be used if not requiredπŸ”’πŸ”§πŸ’­
@typescript-eslint/no-unnecessary-type-assertionWarns if a type assertion does not change the type of an expressionβœ…πŸ”§πŸ’­
@typescript-eslint/no-unnecessary-type-constraintDisallows unnecessary constraints on generic typesβœ…
@typescript-eslint/no-unsafe-argumentDisallows calling a function with an any type valueβœ…πŸ’­
@typescript-eslint/no-unsafe-assignmentDisallows assigning any to variables and propertiesβœ…πŸ’­
@typescript-eslint/no-unsafe-callDisallows calling an any type valueβœ…πŸ’­
@typescript-eslint/no-unsafe-member-accessDisallows member access on any typed variablesβœ…πŸ’­
@typescript-eslint/no-unsafe-returnDisallows returning any from a functionβœ…πŸ’­
@typescript-eslint/no-useless-empty-exportDisallow empty exports that don't change anything in a module fileπŸ”§
@typescript-eslint/no-var-requiresDisallows the use of require statements except in import statementsβœ…
@typescript-eslint/non-nullable-type-assertion-stylePrefers a non-null assertion over explicit type cast when possibleπŸ”’πŸ”§πŸ’­
@typescript-eslint/parameter-propertiesRequire or disallow the use of parameter properties in class constructors
@typescript-eslint/prefer-as-constPrefer usage of as const over literal typeβœ…πŸ”§
@typescript-eslint/prefer-enum-initializersPrefer initializing each enums member value
@typescript-eslint/prefer-for-ofPrefer a β€˜for-of’ loop over a standard β€˜for’ loop if the index is only used to access the array being iteratedπŸ”’
@typescript-eslint/prefer-function-typeUse function types instead of interfaces with call signaturesπŸ”’πŸ”§
@typescript-eslint/prefer-includesEnforce includes method over indexOf methodπŸ”’πŸ”§πŸ’­
@typescript-eslint/prefer-literal-enum-memberRequire that all enum members be literal values to prevent unintended enum member name shadow issuesπŸ”’
@typescript-eslint/prefer-namespace-keywordRequire the use of the namespace keyword instead of the module keyword to declare custom TypeScript modulesβœ…πŸ”§
@typescript-eslint/prefer-nullish-coalescingEnforce the usage of the nullish coalescing operator instead of logical chainingπŸ”’πŸ’­
@typescript-eslint/prefer-optional-chainPrefer using concise optional chain expressions instead of chained logical andsπŸ”’
@typescript-eslint/prefer-readonlyRequires that private members are marked as readonly if they're never modified outside of the constructorπŸ”§πŸ’­
@typescript-eslint/prefer-readonly-parameter-typesRequires that function parameters are typed as readonly to prevent accidental mutation of inputsπŸ’­
@typescript-eslint/prefer-reduce-type-parameterPrefer using type parameter when calling Array#reduce instead of castingπŸ”’πŸ”§πŸ’­
@typescript-eslint/prefer-regexp-execEnforce that RegExp#exec is used instead of String#match if no global flag is providedπŸ”§πŸ’­
@typescript-eslint/prefer-return-this-typeEnforce that this is used when only this type is returnedπŸ”’πŸ”§πŸ’­
@typescript-eslint/prefer-string-starts-ends-withEnforce the use of String#startsWith and String#endsWith instead of other equivalent methods of checking substringsπŸ”’πŸ”§πŸ’­
@typescript-eslint/prefer-ts-expect-errorRecommends using @ts-expect-error over @ts-ignoreπŸ”’πŸ”§
@typescript-eslint/promise-function-asyncRequires any function or method that returns a Promise to be marked asyncπŸ”§πŸ’­
@typescript-eslint/require-array-sort-compareRequires Array#sort calls to always provide a compareFunctionπŸ’­
@typescript-eslint/restrict-plus-operandsWhen adding two variables, operands must both be of type number or of type stringβœ…πŸ’­
@typescript-eslint/restrict-template-expressionsEnforce template literal expressions to be of string typeβœ…πŸ’­
@typescript-eslint/sort-type-union-intersection-membersEnforces that members of a type union/intersection are sorted alphabeticallyπŸ”§
@typescript-eslint/strict-boolean-expressionsRestricts the types allowed in boolean expressionsπŸ”§πŸ’­
@typescript-eslint/switch-exhaustiveness-checkExhaustiveness checking in switch with union typeπŸ’­
@typescript-eslint/triple-slash-referenceSets preference level for triple slash directives versus ES6-style import declarationsβœ…
@typescript-eslint/type-annotation-spacingRequire consistent spacing around type annotationsπŸ”§
@typescript-eslint/typedefRequires type annotations to exist
@typescript-eslint/unbound-methodEnforces unbound methods are called with their expected scopeβœ…πŸ’­
@typescript-eslint/unified-signaturesWarns for any two overloads that could be unified into one by using a union or an optional/rest parameterπŸ”’

Extension Rules​

In some cases, ESLint provides a rule itself, but it doesn't support TypeScript syntax; either it crashes, or it ignores the syntax, or it falsely reports 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.

Key: βœ… = recommended, πŸ”’ = strict, πŸ”§ = fixable, πŸ’­ = requires type information

NameDescriptionβœ…πŸ”’πŸ”§πŸ’­
@typescript-eslint/brace-styleEnforce consistent brace style for blocksπŸ”§
@typescript-eslint/comma-dangleRequire or disallow trailing commaπŸ”§
@typescript-eslint/comma-spacingEnforces consistent spacing before and after commasπŸ”§
@typescript-eslint/default-param-lastEnforce default parameters to be last
@typescript-eslint/dot-notationenforce dot notation whenever possibleπŸ”’πŸ”§πŸ’­
@typescript-eslint/func-call-spacingRequire or disallow spacing between function identifiers and their invocationsπŸ”§
@typescript-eslint/indentEnforce consistent indentationπŸ”§
@typescript-eslint/init-declarationsrequire or disallow initialization in variable declarations
@typescript-eslint/keyword-spacingEnforce consistent spacing before and after keywordsπŸ”§
@typescript-eslint/lines-between-class-membersRequire or disallow an empty line between class membersπŸ”§
@typescript-eslint/no-array-constructorDisallow generic Array constructorsβœ…πŸ”§
@typescript-eslint/no-dupe-class-membersDisallow duplicate class members
@typescript-eslint/no-duplicate-importsDisallow duplicate imports
@typescript-eslint/no-empty-functionDisallow empty functionsβœ…
@typescript-eslint/no-extra-parensDisallow unnecessary parenthesesπŸ”§
@typescript-eslint/no-extra-semiDisallow unnecessary semicolonsβœ…πŸ”§
@typescript-eslint/no-implied-evalDisallow the use of eval()-like methodsβœ…πŸ’­
@typescript-eslint/no-invalid-thisDisallow this keywords outside of classes or class-like objects
@typescript-eslint/no-loop-funcDisallow function declarations that contain unsafe references inside loop statements
@typescript-eslint/no-loss-of-precisionDisallow literal numbers that lose precisionβœ…
@typescript-eslint/no-magic-numbersDisallow magic numbers
@typescript-eslint/no-redeclareDisallow variable redeclaration
@typescript-eslint/no-restricted-importsDisallow specified modules when loaded by import
@typescript-eslint/no-shadowDisallow variable declarations from shadowing variables declared in the outer scope
@typescript-eslint/no-throw-literalDisallow throwing literals as exceptionsπŸ”’πŸ’­
@typescript-eslint/no-unused-expressionsDisallow unused expressions
@typescript-eslint/no-unused-varsDisallow unused variablesβœ…
@typescript-eslint/no-use-before-defineDisallow the use of variables before they are defined
@typescript-eslint/no-useless-constructorDisallow unnecessary constructorsπŸ”’
@typescript-eslint/object-curly-spacingEnforce consistent spacing inside bracesπŸ”§
@typescript-eslint/padding-line-between-statementsrequire or disallow padding lines between statementsπŸ”§
@typescript-eslint/quotesEnforce the consistent use of either backticks, double, or single quotesπŸ”§
@typescript-eslint/require-awaitDisallow async functions which have no await expressionβœ…πŸ’­
@typescript-eslint/return-awaitEnforces consistent returning of awaited valuesπŸ”§πŸ’­
@typescript-eslint/semiRequire or disallow semicolons instead of ASIπŸ”§
@typescript-eslint/space-before-blocksEnforces consistent spacing before blocksπŸ”§
@typescript-eslint/space-before-function-parenEnforces consistent spacing before function parenthesisπŸ”§
@typescript-eslint/space-infix-opsThis rule is aimed at ensuring there are spaces around infix operators.πŸ”§