eslint/rules/types
Types: any, unsafe values, assertions, enums, interfaces, void and null: the type safety of TypeScript. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
79 rules, 61 on. Source: lint/eslint/rules/types.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-prototype-builtins | error | JS + TS | Disallow calling some Object.prototype methods directly on objects | — |
valid-typeof | error | JS + TS | Enforce comparing typeof expressions against valid strings | — |
no-implicit-coercion | error | JS + TS | Disallow shorthand type conversions | — |
no-new-wrappers | error | JS + TS | Disallow new operators with the String, Number, and Boolean objects | — |
no-undefined | off | JS + TS | Disallow the use of undefined as an identifier | — |
no-void | warn, {"allowAsStatement":true} | JS + TS | Disallow void operators | void promise; marks a promise as intentionally not awaited. |
sonarjs/class-prototype | off | JS + TS | Class methods should be used instead of "prototype" assignments | Off: not in the Sonar way profile of SonarQube. |
sonarjs/max-union-size | off | JS + TS | Union types should not have too many elements | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-return-type-any | off | JS + TS | Primitive return types should be used | Off: not in the Sonar way profile of SonarQube. |
sonarjs/deprecation | off | JS + TS | Deprecated APIs should not be used | Off: duplicate of @typescript-eslint/no-deprecated. |
sonarjs/no-primitive-wrappers | off | JS + TS | Wrapper objects should not be used for primitive types | Off: duplicate of no-new-wrappers and @typescript-eslint/no-wrapper-object-types. |
sonarjs/argument-type | warn | JS + TS | Arguments to built-in functions should match documented types | — |
sonarjs/arguments-order | error | JS + TS | Parameters should be passed in the correct order | — |
sonarjs/arguments-usage | off | JS + TS | "arguments" should not be accessed directly | Off: not in the Sonar way profile of SonarQube. |
sonarjs/function-return-type | warn | JS + TS | Functions should always return the same type | — |
sonarjs/no-undefined-argument | warn | JS + TS | "undefined" should not be passed as the value of optional parameters | — |
sonarjs/no-undefined-assignment | off | JS + TS | "undefined" should not be assigned | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-useless-intersection | error | JS + TS | Type intersections should use meaningful types | — |
sonarjs/null-dereference | error | JS + TS | Properties of variables with "null" or "undefined" values should not be accessed | — |
sonarjs/prefer-type-guard | warn | JS + TS | Type predicates should be used | — |
sonarjs/public-static-readonly | warn | JS + TS | Public "static" fields should be read-only | — |
sonarjs/redundant-type-aliases | warn | JS + TS | Redundant type aliases should not be used | — |
sonarjs/use-type-alias | warn | JS + TS | Type aliases should be used | — |
sonarjs/void-use | warn | JS + TS | "void" should not be used | Sonar way; replaces the core @typescript-eslint/no-meaningless-void-operator, like SonarQube. |
@typescript-eslint/adjacent-overload-signatures | info | TS | Require that function overload signatures be consecutive | — |
@typescript-eslint/consistent-generic-constructors | error | TS | Enforce specifying generic type arguments on type annotation or constructor name of a constructor call | — |
@typescript-eslint/consistent-type-assertions | error | TS | Enforce consistent usage of type assertions | — |
@typescript-eslint/consistent-type-definitions | error | TS | Enforce type definitions to consistently use either interface or type | — |
@typescript-eslint/consistent-type-exports | error | TS | Enforce consistent usage of type exports | — |
@typescript-eslint/consistent-type-imports | error | TS | Enforce consistent usage of type imports | — |
@typescript-eslint/explicit-function-return-type | error | TS | Require explicit return types on functions and class methods | — |
@typescript-eslint/explicit-module-boundary-types | off | TS | Require explicit return and argument types on exported functions' and classes' public class methods | Off: duplicate of explicit-function-return-type. |
@typescript-eslint/method-signature-style | error, "method" | TS | Enforce using a particular method signature syntax | Custom: foo(): void style; pass members as callbacks through () => api.foo(). |
@typescript-eslint/no-confusing-non-null-assertion | off | TS | Disallow non-null assertion in locations that may be confusing | Off: no-non-null-assertion forbids every !. |
@typescript-eslint/no-confusing-void-expression | error | TS | Require expressions of type void to appear in statement position | — |
@typescript-eslint/no-deprecated | warn | TS | Disallow using code marked as @deprecated | Warn: a deprecated API may have no replacement yet. |
@typescript-eslint/no-duplicate-enum-values | error | TS | Disallow duplicate enum member values | — |
@typescript-eslint/no-duplicate-type-constituents | error | TS | Disallow duplicate constituents of union or intersection types | — |
@typescript-eslint/no-empty-interface | off | TS | Disallow the declaration of empty interfaces | Deprecated: replaced by no-empty-object-type. |
@typescript-eslint/no-empty-object-type | warn | TS | Disallow accidentally using the "empty object" type | — |
@typescript-eslint/no-explicit-any | warn | TS | Disallow the any type | Warn: an any is justified where it is written (off in a library: rules/library). Using an any value stays an error (no-unsafe-*). |
@typescript-eslint/no-extra-non-null-assertion | off | TS | Disallow extra non-null assertions | Off: no-non-null-assertion forbids every !. |
@typescript-eslint/no-generated-empty-object-type | error | TS | Disallow type operations that resolve to the "empty object" type | — |
@typescript-eslint/no-import-type-side-effects | error | TS | Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers | — |
@typescript-eslint/no-inferrable-types | error | TS | Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean | — |
@typescript-eslint/no-invalid-void-type | warn | TS | Disallow void type outside of generic or return types | Warn: a void in a union or a generic is justified where it is written (off in a library: rules/library). |
@typescript-eslint/no-meaningless-void-operator | off | TS | Disallow the void operator except when used to discard a value | Off: replaced by sonarjs/void-use, like SonarQube. |
@typescript-eslint/no-mixed-enums | error | TS | Disallow enums from having both number and string members | — |
@typescript-eslint/no-non-null-asserted-nullish-coalescing | off | TS | Disallow non-null assertions in the left operand of a nullish coalescing operator | Off: no-non-null-assertion forbids every !. |
@typescript-eslint/no-non-null-asserted-optional-chain | off | TS | Disallow non-null assertions after an optional chain expression | — |
@typescript-eslint/no-non-null-assertion | warn | TS | Disallow non-null assertions using the ! postfix operator | Warn: a value the types cannot prove present. |
@typescript-eslint/no-redundant-type-constituents | info | TS | Disallow members of unions and intersections that do nothing or override type information | — |
@typescript-eslint/no-restricted-types | error | TS | Disallow certain types | — |
@typescript-eslint/no-type-alias | off | TS | Disallow type aliases | Deprecated: replaced by consistent-type-definitions. |
@typescript-eslint/no-unnecessary-type-arguments | error | TS | Disallow type arguments that are equal to the default | — |
@typescript-eslint/no-unnecessary-type-assertion | error | TS | Disallow type assertions that do not change the type of an expression | — |
@typescript-eslint/no-unnecessary-type-constraint | info | TS | Disallow unnecessary constraints on generic types | — |
@typescript-eslint/no-unnecessary-type-conversion | info | TS | Disallow conversion idioms when they do not change the type or value of the expression | — |
@typescript-eslint/no-unnecessary-type-parameters | error | TS | Disallow type parameters that aren't used multiple times | — |
@typescript-eslint/no-unsafe-argument | error | TS | Disallow calling a function with a value with type any | Using an any value breaks the typing: an error, never disabled. |
@typescript-eslint/no-unsafe-assignment | error | TS | Disallow assigning a value with type any to variables and properties | Using an any value breaks the typing: an error, never disabled. |
@typescript-eslint/no-unsafe-call | error | TS | Disallow calling a value with type any | Using an any value breaks the typing: an error, never disabled. |
@typescript-eslint/no-unsafe-declaration-merging | error | TS | Disallow unsafe declaration merging | — |
@typescript-eslint/no-unsafe-enum-assignment | error | TS | Disallow assigning non-enum values to enum typed locations | — |
@typescript-eslint/no-unsafe-function-type | warn | TS | Disallow using the unsafe built-in Function type | Warn: generic or external code sometimes needs it. |
@typescript-eslint/no-unsafe-member-access | error | TS | Disallow member access on a value with type any | Using an any value breaks the typing: an error, never disabled. |
@typescript-eslint/no-unsafe-return | error | TS | Disallow returning a value with type any from a function | Using an any value breaks the typing: an error, never disabled. |
@typescript-eslint/no-unsafe-type-assertion | warn | TS | Disallow type assertions that narrow a type | Warn: narrowing an external type sometimes needs an assertion. |
@typescript-eslint/no-wrapper-object-types | error | TS | Disallow using confusing built-in primitive class wrappers | — |
@typescript-eslint/non-nullable-type-assertion-style | off | TS | Enforce non-null assertions over explicit type assertions | Off: asks for x!, forbidden by no-non-null-assertion. |
@typescript-eslint/prefer-enum-initializers | info | TS | Require each enum member value to be explicitly initialized | — |
@typescript-eslint/prefer-function-type | error | TS | Enforce using function types instead of interfaces with call signatures | — |
@typescript-eslint/prefer-literal-enum-member | info | TS | Require all enum members to be literal values | — |
@typescript-eslint/prefer-readonly | error | TS | Require private members to be marked as readonly if they're never modified outside of the constructor | — |
@typescript-eslint/prefer-readonly-parameter-types | warn, {"ignoreInferredTypes":true,"treatMethodsAsReadonly":true… | TS | Require function parameters to be typed as readonly to prevent accidental mutation of inputs | Custom: a utility never mutates its arguments; functions and DOM/runtime types (live objects) are exempt. Warn: external types (DOM, libraries) are not deeply readonly. |
@typescript-eslint/prefer-return-this-type | error | TS | Enforce that this is used when only this type is returned | — |
@typescript-eslint/strict-void-return | error | TS | Disallow passing a value-returning function in a position accepting a void function | — |
@typescript-eslint/typedef | off | TS | Require type annotations in certain places | Deprecated: no replacement. |
@typescript-eslint/unified-signatures | info | TS | Disallow two overloads that could be unified into one with a union or an optional/rest parameter | — |