TypeScript
TypeScript-only rules and @typescript-eslint plugin equivalents, exposed under the typescript/* namespace. Each rule either requires TypeScript syntax (interface, enum, namespace, as, !, import type, type parameters, declaration merging, parameter properties, triple-slash references) or originates from @typescript-eslint as a TS-aware extension that has no counterpart in plain ESLint. Generic JS/TS rules stay unnamespaced in Core.
Source: typescript-eslint (MIT).
typescript/adjacent-overload-signatures: Require overload declarations for the same member to be written adjacently.typescript/array-type: Enforce one consistent spelling of array types.typescript/await-thenable: Rejectawaiton operands that are not thenable.typescript/ban-ts-comment: Reject@ts-ignore,@ts-expect-error,@ts-nocheck, and@ts-checkcomments.typescript/ban-tslint-comment: Reject// tslint:disableand related TSLint directive comments left behind from the legacy TSLint era.typescript/class-literal-property-style: Prefer astatic readonlyfield over agetaccessor whose body is a singlereturn <literal>;.typescript/consistent-generic-constructors: Reject the redundant pattern where a variable is annotated with a generic type AND the same generic arguments are repeated on the constructor:const m: Map<K, V> = new Map<K, V>().typescript/consistent-indexed-object-style: PreferRecord<K, V>over{ [key: K]: V }when an object type has a single index signature and no other members.typescript/consistent-type-assertions: Prefer theasform of type assertions over the angle-bracket form<T>expr, which is ambiguous inside JSX.typescript/consistent-type-definitions: Enforce one consistent shape for object types.typescript/consistent-type-exports: require type-only re-exports to useexport type { ... }instead of mixing them with value-level re-exports.typescript/consistent-type-imports: Require imports that only reference types to useimport type {}so the import has no runtime cost.typescript/explicit-function-return-type: require every exported function and method declaration to carry an explicit return-type annotation.typescript/explicit-member-accessibility: Require an explicit accessibility modifier (public,private, orprotected) on every class member declaration.typescript/method-signature-style: Prefer a function-property signature (f: () => void) over a shorthand method signature (f(): void) in interfaces and type literals so the strict-function-types contravariance check applies.typescript/no-array-delete: Rejectdelete arr[i]against array elements.typescript/no-array-for-each: Preferfor ... ofoverArray.prototype.forEach().typescript/no-base-to-string: reject string-coercion contexts (`${x}`,x + "",String(x)) wherexhas a type whosetoStringresolves to the defaultObject.prototype.toStringand would print"[object Object]".typescript/no-confusing-non-null-assertion: Reject non-null assertions placed where they visually merge with a following operator,a! == b(reads as!=),a! in b, ora! instanceof B.typescript/no-confusing-void-expression: Rejectvoid Xexpressions used in any position where the surrounding context expects a value, initializer, call argument,returnoperand, conditional, binary, or ternary subexpression.typescript/no-deprecated: reject references to declarations marked@deprecatedin their JSDoc.typescript/no-duplicate-enum-values: Rejectenumdeclarations whose members share the same literal value.typescript/no-dynamic-delete: Reject computed bracket-keydeleteexpressions (delete obj[x]) wherexis not a string literal, since these escape type tracking.typescript/no-empty-interface: Reject emptyinterfacedeclarations.typescript/no-empty-object-type: Reject{}as a type annotation.typescript/no-explicit-any: Rejectanytype annotations.typescript/no-extra-non-null-assertion: Rejectx!!, chained non-null assertions where the inner one already removes nullability.typescript/no-extraneous-class: Reject classes that exist purely as a namespace for static members or that are entirely empty.typescript/no-floating-promises: Reject Promise-typed expressions whose result is discarded, most often a baregetPromise();expression statement.typescript/no-for-in-array: Rejectfor (const k in arr)wherearris statically typed as an array or tuple,for...inyields enumerable property names, not array values.typescript/no-import-type-side-effects: Hoist inlinetypemodifiers on individual imports into a single top-levelimport type {}.typescript/no-inferrable-types: Reject explicit type annotations that TypeScript can already infer from the initializer (const x: number = 1).typescript/no-invalid-void-type: Rejectvoidused as anything other than a function return type.typescript/no-magic-numbers: TypeScript-aware extension ofno-magic-numbersthat additionally ignores enum member values.typescript/no-meaningless-void-operator: Rejectvoid XwhereXis already statically typedvoid, the operator adds nothing because the operand already evaluates toundefined(type-aware).typescript/no-misused-new: Reject signatures that fake a constructor or an instancenewmethod,interface I { new (): I }(TypeScript treats this as the type ofnew I()regardless of intent) andclass C { new(): C }.typescript/no-misused-promises: Reject Promise values supplied where a non-Promise was expected.typescript/no-misused-spread: Reject spread expressions whose operand is syntactically wrong for the surrounding context.typescript/no-mixed-enums: Rejectenums that mix numeric and string members, which makes the resulting type unsafe for reverse lookups.typescript/no-namespace: Reject non-ambientnamespaceandmodule Foo {}declarations in regular.tsfiles.typescript/no-non-null-asserted-nullish-coalescing: Rejectx! ?? y. The!collapsesnull | undefinedto a non-nullish value, so the??branch is unreachable.typescript/no-non-null-asserted-optional-chain: Rejectx!?.y. The non-null assertion makes the optional chain meaningless because the inner expression is already known to be defined.typescript/no-non-null-assertion: Reject postfix!non-null assertions altogether.typescript/no-redundant-type-constituents: reject union and intersection type constituents that the type system absorbs anyway,string | anycollapses toany,T & nevercollapses tonever,T & unknowncollapses toT, and repeated constituents add nothing.typescript/no-require-imports: Rejectrequire(...)calls andimport x = require(...)declarations.typescript/no-restricted-types: reject specific type-reference names that are almost always a mistake, by default the global wrapper typesObject,Function,Number,String, andBoolean.typescript/no-this-alias: Reject aliasingthisto a local (const self = this,const that = this, destructuringconst { x } = this).typescript/no-unnecessary-boolean-literal-compare: reject direct comparison of a boolean-typed value withtrue/falseliterals,x === trueis justx,x !== falseis justx.typescript/no-unnecessary-condition: Reject conditions whose static type proves the runtime truthiness is fixed,if ({}),if (null),while (""),0 && f().typescript/no-unnecessary-parameter-property-assignment: Rejectthis.x = xin a constructor body whenxis already declared as a parameter property, TypeScript performs the assignment automatically.typescript/no-unnecessary-qualifier: Reject namespace/enum qualifiers that the surrounding scope makes unnecessary, insidenamespace Foo { Foo.bar }theFoo.prefix can be dropped.typescript/no-unnecessary-template-expression: reject template literals that carry no template-only behavior, a`${"abc"}`interpolation, a lone`${name}`span around a string-typed value, or a`abc`no-substitution literal with no escaped backticks.typescript/no-unnecessary-type-arguments: rejectFoo<DefaultT>calls where the supplied generic argument is the same as the parameter’s default.typescript/no-unnecessary-type-assertion: Rejectx as T,<T>x, andx!assertions whose target type is the same asx’s already-known static type, the assertion adds nothing (type-aware).typescript/no-unnecessary-type-constraint: Reject<T extends unknown>and similar constraints that match everything.typescript/no-unsafe-argument: Reject passing anany-typed value to a parameter whose declared type is concrete, theanyenters the callee with type-checking disabled (type-aware).typescript/no-unsafe-assignment: Reject assigning anany-typed value to a variable, parameter, or property whose declared type is concrete (type-aware).typescript/no-unsafe-call: Reject calling a value whose static type isany(type-aware).typescript/no-unsafe-declaration-merging: Reject declaration merging between aninterfaceand aclasswith the same name.typescript/no-unsafe-enum-comparison: Reject==/===/!=/!==comparisons between an enum-typed value and a plainnumberorstringof the same widened primitive, the comparison silently accepts unrelated enums and raw literals that happen to share the underlying primitive.typescript/no-unsafe-function-type: Reject the unsafeFunctiontype, which matches every callable regardless of signature.typescript/no-unsafe-member-access: Reject member access (x.foo,x[key]) on a value whose static type isany(type-aware).typescript/no-unsafe-return: Reject areturnexpression whose static type isanyfrom a function whose declared return type is a concrete (non-any/ non-unknown/ non-void) shape, theanyleaks past the type boundary and disables every downstream check on the returned value.typescript/no-unsafe-unary-minus: Reject the unary-operator applied to an operand whose static type is not number-like or bigint-like,-xsilently coerces strings, objects, and other shapes viaNumber(x)and almost always indicates a bug.typescript/no-useless-constructor: TypeScript-aware extension ofno-useless-constructorthat tolerates a constructor existing solely to expose parameter properties.typescript/no-useless-empty-export: Reject redundantexport {}declarations in module files.typescript/no-wrapper-object-types: Reject the wrapper object typesString,Number,Boolean,Symbol, andBigInt.typescript/non-nullable-type-assertion-style: rejectx as Fooassertions whose target type is the non-nullable version ofx’s static type. Replace with the shorterx!non-null assertion.typescript/only-throw-error: Rejectthrow XwhereXis statically known not to derive fromError, string literals, numbers, plain object literals, and the like.typescript/parameter-properties: Reject TypeScript parameter-property constructors (constructor(public foo: T)). Prefer plain field declarations so the class shape is visible from the member list instead of buried in the constructor parameter list.typescript/prefer-as-const: Preferas constoveras "literal"assertions.typescript/prefer-enum-initializers: Require everyenummember to have an explicit initializer.typescript/prefer-find: Preferarray.find(predicate)overarray.filter(predicate)[0]/.shift()when only the first match is needed.typescript/prefer-function-type: Prefer a type alias over an interface that declares only a single call signature, the type form composes better with structural typing.typescript/prefer-includes: Preferarray.includes(x)overarray.indexOf(x) !== -1(and the matching=== -1,>= 0,< 0,> -1shapes) on array, tuple, and string receivers.typescript/prefer-literal-enum-member: Prefer literal initializers (= 0,= "FOO") for enum members over computed expressions, so the value is decidable at compile time.typescript/prefer-namespace-keyword: Prefer thenamespacekeyword over the legacymodule Foo {}form.typescript/prefer-nullish-coalescing: prefer??over||(and??=over||=, and??over the ternaryx ? x : y) when the intent is to defaultnull/undefined.typescript/prefer-optional-chain: prefer an optional chain (a?.b?.c) over chained boolean guards such asa && a.b && a.b.cora != null && a.b.typescript/prefer-promise-reject-errors: RejectPromise.reject(value)wherevalueis statically known not to derive fromError, type-aware analog ofonly-throw-errorfor the rejection side of the promise contract.typescript/prefer-readonly: reject private class fields that could carryreadonly.typescript/prefer-reduce-type-parameter: Preferarr.reduce<T>(..., initial)overarr.reduce(..., initial as T)so the accumulator type is fixed at the call site instead of widened inside the initial-value assertion.typescript/prefer-regexp-exec: Preferregex.exec(str)overstr.match(regex)when the regex carries thegflag, where.matchreturns only the matched substrings and discards capture groups.typescript/prefer-return-this-type: Prefer the explicitthisreturn type for chainable methods over the surrounding class name, fluent subclasses preserve their concretethisinstead of widening to the base.typescript/prefer-string-starts-ends-with: Preferstr.startsWith(p)/str.endsWith(p)overstr.indexOf(p) === 0,str.indexOf(p, str.length - p.length) !== -1,str.lastIndexOf(p) === str.length - p.length, and the anchored-regex/^p/.test(str)//p$/.test(str)idioms.typescript/promise-function-async: Require functions whose return type isPromise<T>to be declared with theasynckeyword so synchronous throws surface as a rejected Promise.typescript/related-getter-setter-pairs: Reject agetaccessor whose declared return type does not match the parameter type of its companionsetaccessor on the same class, readers should not observe a type the writer cannot accept (type-aware).typescript/require-array-sort-compare: requirearr.sort()andarr.toSorted()calls to pass an explicitcompareFunction.typescript/require-await: Rejectasyncfunctions whose body contains noawaitexpression.typescript/restrict-plus-operands: reject+expressions whose operands are not bothnumber, bothstring, or bothbigint.typescript/restrict-template-expressions: reject template-literal interpolations whose expression carries a type that does not stringify cleanly,${obj}prints"[object Object]",${null}prints"null", and so on.typescript/return-await: Rejectreturn promiseinsidetry,catch, orfinally; requirereturn await promise.typescript/sort-type-constituents: Sort the members of union (A | B | C) and intersection (A & B & C) types into a canonical order so reorderings don’t show up as diffs.typescript/strict-boolean-expressions: Reject non-boolean values used in a boolean context such asif,&&,||, or!. Name the intent with an explicit comparison.typescript/switch-exhaustiveness-check: require every member of a union orenumdiscriminant to be covered by an explicitcase, unless adefaultclause is present.typescript/triple-slash-reference: Reject/// <reference path="..." />,/// <reference types="" />, and/// <reference lib="" />directives.typescript/unbound-method: reject referencing a class instance method as a value instead of calling it (obj.methodpassed as a callback, aliased to a variable, or stored on another object).typescript/use-unknown-in-catch-callback-variable: Require the callback parameter of.catch(...)and the second argument of.then(...)to be typedunknown.
Last updated on