Skip to content

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.

RuleSettingFilesWhat it checksWhy
no-prototype-builtinserrorJS + TSDisallow calling some Object.prototype methods directly on objects—
valid-typeoferrorJS + TSEnforce comparing typeof expressions against valid strings—
no-implicit-coercionerrorJS + TSDisallow shorthand type conversions—
no-new-wrapperserrorJS + TSDisallow new operators with the String, Number, and Boolean objects—
no-undefinedoffJS + TSDisallow the use of undefined as an identifier—
no-voidwarn, {"allowAsStatement":true}JS + TSDisallow void operatorsvoid promise; marks a promise as intentionally not awaited.
sonarjs/class-prototypeoffJS + TSClass methods should be used instead of "prototype" assignmentsOff: not in the Sonar way profile of SonarQube.
sonarjs/max-union-sizeoffJS + TSUnion types should not have too many elementsOff: not in the Sonar way profile of SonarQube.
sonarjs/no-return-type-anyoffJS + TSPrimitive return types should be usedOff: not in the Sonar way profile of SonarQube.
sonarjs/deprecationoffJS + TSDeprecated APIs should not be usedOff: duplicate of @typescript-eslint/no-deprecated.
sonarjs/no-primitive-wrappersoffJS + TSWrapper objects should not be used for primitive typesOff: duplicate of no-new-wrappers and @typescript-eslint/no-wrapper-object-types.
sonarjs/argument-typewarnJS + TSArguments to built-in functions should match documented types—
sonarjs/arguments-ordererrorJS + TSParameters should be passed in the correct order—
sonarjs/arguments-usageoffJS + TS"arguments" should not be accessed directlyOff: not in the Sonar way profile of SonarQube.
sonarjs/function-return-typewarnJS + TSFunctions should always return the same type—
sonarjs/no-undefined-argumentwarnJS + TS"undefined" should not be passed as the value of optional parameters—
sonarjs/no-undefined-assignmentoffJS + TS"undefined" should not be assignedOff: not in the Sonar way profile of SonarQube.
sonarjs/no-useless-intersectionerrorJS + TSType intersections should use meaningful types—
sonarjs/null-dereferenceerrorJS + TSProperties of variables with "null" or "undefined" values should not be accessed—
sonarjs/prefer-type-guardwarnJS + TSType predicates should be used—
sonarjs/public-static-readonlywarnJS + TSPublic "static" fields should be read-only—
sonarjs/redundant-type-aliaseswarnJS + TSRedundant type aliases should not be used—
sonarjs/use-type-aliaswarnJS + TSType aliases should be used—
sonarjs/void-usewarnJS + TS"void" should not be usedSonar way; replaces the core @typescript-eslint/no-meaningless-void-operator, like SonarQube.
@typescript-eslint/adjacent-overload-signaturesinfoTSRequire that function overload signatures be consecutive—
@typescript-eslint/consistent-generic-constructorserrorTSEnforce specifying generic type arguments on type annotation or constructor name of a constructor call—
@typescript-eslint/consistent-type-assertionserrorTSEnforce consistent usage of type assertions—
@typescript-eslint/consistent-type-definitionserrorTSEnforce type definitions to consistently use either interface or type—
@typescript-eslint/consistent-type-exportserrorTSEnforce consistent usage of type exports—
@typescript-eslint/consistent-type-importserrorTSEnforce consistent usage of type imports—
@typescript-eslint/explicit-function-return-typeerrorTSRequire explicit return types on functions and class methods—
@typescript-eslint/explicit-module-boundary-typesoffTSRequire explicit return and argument types on exported functions' and classes' public class methodsOff: duplicate of explicit-function-return-type.
@typescript-eslint/method-signature-styleerror, "method"TSEnforce using a particular method signature syntaxCustom: foo(): void style; pass members as callbacks through () => api.foo().
@typescript-eslint/no-confusing-non-null-assertionoffTSDisallow non-null assertion in locations that may be confusingOff: no-non-null-assertion forbids every !.
@typescript-eslint/no-confusing-void-expressionerrorTSRequire expressions of type void to appear in statement position—
@typescript-eslint/no-deprecatedwarnTSDisallow using code marked as @deprecatedWarn: a deprecated API may have no replacement yet.
@typescript-eslint/no-duplicate-enum-valueserrorTSDisallow duplicate enum member values—
@typescript-eslint/no-duplicate-type-constituentserrorTSDisallow duplicate constituents of union or intersection types—
@typescript-eslint/no-empty-interfaceoffTSDisallow the declaration of empty interfacesDeprecated: replaced by no-empty-object-type.
@typescript-eslint/no-empty-object-typewarnTSDisallow accidentally using the "empty object" type—
@typescript-eslint/no-explicit-anywarnTSDisallow the any typeWarn: 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-assertionoffTSDisallow extra non-null assertionsOff: no-non-null-assertion forbids every !.
@typescript-eslint/no-generated-empty-object-typeerrorTSDisallow type operations that resolve to the "empty object" type—
@typescript-eslint/no-import-type-side-effectserrorTSEnforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers—
@typescript-eslint/no-inferrable-typeserrorTSDisallow explicit type declarations for variables or parameters initialized to a number, string, or boolean—
@typescript-eslint/no-invalid-void-typewarnTSDisallow void type outside of generic or return typesWarn: 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-operatoroffTSDisallow the void operator except when used to discard a valueOff: replaced by sonarjs/void-use, like SonarQube.
@typescript-eslint/no-mixed-enumserrorTSDisallow enums from having both number and string members—
@typescript-eslint/no-non-null-asserted-nullish-coalescingoffTSDisallow non-null assertions in the left operand of a nullish coalescing operatorOff: no-non-null-assertion forbids every !.
@typescript-eslint/no-non-null-asserted-optional-chainoffTSDisallow non-null assertions after an optional chain expression—
@typescript-eslint/no-non-null-assertionwarnTSDisallow non-null assertions using the ! postfix operatorWarn: a value the types cannot prove present.
@typescript-eslint/no-redundant-type-constituentsinfoTSDisallow members of unions and intersections that do nothing or override type information—
@typescript-eslint/no-restricted-typeserrorTSDisallow certain types—
@typescript-eslint/no-type-aliasoffTSDisallow type aliasesDeprecated: replaced by consistent-type-definitions.
@typescript-eslint/no-unnecessary-type-argumentserrorTSDisallow type arguments that are equal to the default—
@typescript-eslint/no-unnecessary-type-assertionerrorTSDisallow type assertions that do not change the type of an expression—
@typescript-eslint/no-unnecessary-type-constraintinfoTSDisallow unnecessary constraints on generic types—
@typescript-eslint/no-unnecessary-type-conversioninfoTSDisallow conversion idioms when they do not change the type or value of the expression—
@typescript-eslint/no-unnecessary-type-parameterserrorTSDisallow type parameters that aren't used multiple times—
@typescript-eslint/no-unsafe-argumenterrorTSDisallow calling a function with a value with type anyUsing an any value breaks the typing: an error, never disabled.
@typescript-eslint/no-unsafe-assignmenterrorTSDisallow assigning a value with type any to variables and propertiesUsing an any value breaks the typing: an error, never disabled.
@typescript-eslint/no-unsafe-callerrorTSDisallow calling a value with type anyUsing an any value breaks the typing: an error, never disabled.
@typescript-eslint/no-unsafe-declaration-mergingerrorTSDisallow unsafe declaration merging—
@typescript-eslint/no-unsafe-enum-assignmenterrorTSDisallow assigning non-enum values to enum typed locations—
@typescript-eslint/no-unsafe-function-typewarnTSDisallow using the unsafe built-in Function typeWarn: generic or external code sometimes needs it.
@typescript-eslint/no-unsafe-member-accesserrorTSDisallow member access on a value with type anyUsing an any value breaks the typing: an error, never disabled.
@typescript-eslint/no-unsafe-returnerrorTSDisallow returning a value with type any from a functionUsing an any value breaks the typing: an error, never disabled.
@typescript-eslint/no-unsafe-type-assertionwarnTSDisallow type assertions that narrow a typeWarn: narrowing an external type sometimes needs an assertion.
@typescript-eslint/no-wrapper-object-typeserrorTSDisallow using confusing built-in primitive class wrappers—
@typescript-eslint/non-nullable-type-assertion-styleoffTSEnforce non-null assertions over explicit type assertionsOff: asks for x!, forbidden by no-non-null-assertion.
@typescript-eslint/prefer-enum-initializersinfoTSRequire each enum member value to be explicitly initialized—
@typescript-eslint/prefer-function-typeerrorTSEnforce using function types instead of interfaces with call signatures—
@typescript-eslint/prefer-literal-enum-memberinfoTSRequire all enum members to be literal values—
@typescript-eslint/prefer-readonlyerrorTSRequire private members to be marked as readonly if they're never modified outside of the constructor—
@typescript-eslint/prefer-readonly-parameter-typeswarn, {"ignoreInferredTypes":true,"treatMethodsAsReadonly":true…TSRequire function parameters to be typed as readonly to prevent accidental mutation of inputsCustom: 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-typeerrorTSEnforce that this is used when only this type is returned—
@typescript-eslint/strict-void-returnerrorTSDisallow passing a value-returning function in a position accepting a void function—
@typescript-eslint/typedefoffTSRequire type annotations in certain placesDeprecated: no replacement.
@typescript-eslint/unified-signaturesinfoTSDisallow two overloads that could be unified into one with a union or an optional/rest parameter—

Generated from the JSDoc of the sources.