Skip to content

TypeScript ​

This page documents 79 rules from the current dependency versions and repository configuration. Each entry includes effective severity, scope, upstream description, common messages, and incorrect/correct examples.

Explicit repository rules (47 rules) ​

@typescript-eslint/class-literal-property-style ​

Does not force readonly literal class properties into either getter or field syntax.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Literals should be exposed using readonly fields.; Replace the literals with readonly fields.; Literals should be exposed using getters.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
class Status { get ready(): "ready" { return "ready"; } }

Correct:

ts
class Status { readonly ready = "ready" as const; }

@typescript-eslint/consistent-indexed-object-style ​

Does not mandate index signatures, Record, or mapped types over one another.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: An index signature is preferred over a record.; Change into an index signature instead of a record.; A record is preferred over an index signature.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
type Scores = { [name: string]: number };

Correct:

ts
type Scores = Record<string, number>;

@typescript-eslint/consistent-type-definitions &ZeroWidthSpace;

Does not mandate interface or type as the only type-definition form.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Use an 'interface' instead of a 'type'.; Use a 'type' instead of an 'interface'.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
type User = { id: number };

Correct:

ts
interface User { id: number }

@typescript-eslint/consistent-type-exports &ZeroWidthSpace;

Use export type for type-only exports to avoid implying nonexistent runtime exports.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Type exports {{exportNames}} are not values and should be exported using 'export type'.; Type export {{exportNames}} is not a value and should be exported using 'export type'.; All exports in the declaration are only used as types. Use 'export type'.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface User { id: string }
export { User };

Correct:

ts
interface User { id: string }
export type { User };

@typescript-eslint/consistent-type-imports &ZeroWidthSpace;

Use separate import type declarations for type-only dependencies, avoiding unnecessary runtime imports.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Use an 'import' instead of an 'import type'.; 'import()' type annotations are forbidden.; Imports {{typeImports}} are only used as type.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
import { Stats } from "node:fs";
export const getSize = (stats: Stats): number => stats.size;

Correct:

ts
import type { Stats } from "node:fs";
export const getSize = (stats: Stats): number => stats.size;

@typescript-eslint/explicit-function-return-type &ZeroWidthSpace;

SFC template work and rapid iteration do not require explicit function return annotations.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Missing return type on function.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
function load() { return 1; }

Correct:

ts
function load(): number { return 1; }

@typescript-eslint/explicit-module-boundary-types &ZeroWidthSpace;

Vue compiler macros establish SFC export contracts; ordinary module-boundary annotations are not mandatory.

  • Effective severity and scope: error: TypeScript base, Angular TypeScript
  • Disabled in: Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Argument '{{name}}' should be typed with a non-any type.; {{type}} argument should be typed with a non-any type.; Argument '{{name}}' should be typed.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
export const add = (left, right) => left + right;

Correct:

ts
export const add = (left: number, right: number): number => left + right;

@typescript-eslint/no-confusing-void-expression &ZeroWidthSpace;

Allows concise () => notify() callbacks while checking other confusing uses of void-valued expressions.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Placing a void expression inside another expression is forbidden. Move it to its own statement instead.; Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.; Void expressions returned from an arrow function shorthand must be marked explicitly with the 'void' operator.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const result = console.log("saved");

Correct:

ts
console.log("saved");

@typescript-eslint/no-deprecated &ZeroWidthSpace;

Deprecated APIs remain visible as warnings without blocking compatibility across dependency versions.

  • Effective severity and scope: warn: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: '{{name}}' is deprecated.; '{{name}}' is deprecated. {{reason}}
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
/** @deprecated Use loadCurrent instead. */
declare function loadLegacy(): void;
loadLegacy();

Correct:

ts
declare function loadCurrent(): void;
loadCurrent();

@typescript-eslint/no-dynamic-delete &ZeroWidthSpace;

Dynamic object property deletion is normal for forms and dictionaries; separate rules still prohibit array delete.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Do not delete dynamically computed property keys.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare const record: Record<string, number>;
declare const key: string;
delete record[key];

Correct:

ts
declare const record: Record<string, number>;
declare const key: string;
const { [key]: removedValue, ...remaining } = record;
use(removedValue, remaining);

@typescript-eslint/no-empty-function &ZeroWidthSpace;

Disallows unintentionally empty functions, except constructors and intentionally empty overrides.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unexpected empty {{name}}.; Add comment inside empty {{name}}.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const save = (): void => {};

Correct:

ts
const save = (): void => { persist(); };

@typescript-eslint/no-explicit-any &ZeroWidthSpace;

Any bypasses type checks but may be needed at third-party boundaries or during migration, so it only warns.

  • Effective severity and scope: warn: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Use 'never' instead, this is useful when instantiating generic type parameters that you don't need to know the type of.; Use 'PropertyKey' instead, this is more explicit than 'keyof any'.; Use 'unknown' instead, this will force you to explicitly, and safely assert the type is correct.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
function parse(value: any): any { return value; }

Correct:

ts
function parse(value: unknown): unknown { return value; }

@typescript-eslint/no-extraneous-class &ZeroWidthSpace;

Static utility classes may be intentional SDK APIs; conversion to functions or objects is not mandatory.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unexpected empty class.; Unexpected class with only a constructor.; Unexpected class with only static properties.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
class MathTools { static double(value: number): number { return value * 2; } }

Correct:

ts
const double = (value: number): number => value * 2;

@typescript-eslint/no-floating-promises &ZeroWidthSpace;

Developers decide whether to await, return, or handle Promises based on ordering and error semantics.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler.; Add await operator.; Add void operator to ignore.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare function loadData(): Promise<void>;
loadData();

Correct:

ts
declare function loadData(): Promise<void>;
await loadData();

@typescript-eslint/no-import-type-side-effects &ZeroWidthSpace;

Promotes inline type-only imports to separate import type declarations, avoiding runtime imports used only for types.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: TypeScript will only remove the inline type specifiers which will leave behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
import { type User } from "./types";

Correct:

ts
import type { User } from "./types";

@typescript-eslint/no-inferrable-types &ZeroWidthSpace;

Removes inferable primitive annotations from local variables; parameters and properties may retain contract/documentation annotations.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Type {{type}} trivially inferred from a {{type}} literal, remove type annotation.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const count: number = 1;

Correct:

ts
const count = 1;

@typescript-eslint/no-meaningless-void-operator &ZeroWidthSpace;

Core no-void already prohibits the void operator; duplicate type-aware diagnostics are disabled.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: void operator is useless here; it should only discard a call's return value; void operator shouldn't be used on {{type}}; it should convey that a return value is being ignored; Remove 'void'
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare function logSaved(): void;
void logSaved();

Correct:

ts
declare function logSaved(): void;
logSaved();

@typescript-eslint/no-misused-promises &ZeroWidthSpace;

Vue owns asynchronous template-event results, so Promise-returning handlers are allowed; other Promise misuse remains checked.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Expected non-Promise value in a boolean conditional.; Expected a non-Promise value to be returned.; Expected a non-Promise value to be spread in an object.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare function fetchReady(): Promise<boolean>;
if (fetchReady()) { start(); }

Correct:

ts
declare function fetchReady(): Promise<boolean>;
if (await fetchReady()) { start(); }

@typescript-eslint/no-misused-spread &ZeroWidthSpace;

Disallows spreading statically known noniterable or semantically incompatible values.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Add await operator.; Using the spread operator on an array in an object will result in a list of indices.; Using the spread operator on class declarations will spread only their static properties, and will lose their class prototype.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface User { name: string }
declare function loadUser(): Promise<User>;
const result = { ...loadUser() };

Correct:

ts
interface User { name: string }
declare function loadUser(): Promise<User>;
const result = { ...(await loadUser()) };

@typescript-eslint/no-mixed-enums &ZeroWidthSpace;

Do not mix value categories within an enum; this makes comparison and serialization inconsistent.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Mixing number and string enums can be confusing.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
enum Status { Ready = "ready", Failed = 1 }

Correct:

ts
enum Status { Ready = "ready", Failed = "failed" }

@typescript-eslint/no-namespace &ZeroWidthSpace;

Namespaces remain useful in declaration files, global augmentations, and some SDKs.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: ES2015 module syntax is preferred over namespaces.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
namespace Format { export const trim = (value: string): string => value.trim(); }

Correct:

ts
export const trim = (value: string): string => value.trim();

@typescript-eslint/no-non-null-asserted-nullish-coalescing &ZeroWidthSpace;

Combining a non-null assertion with nullish coalescing is contradictory.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: The nullish coalescing operator is designed to handle undefined and null - using a non-null assertion is not needed.; Remove the non-null assertion.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const value = input! ?? fallback;

Correct:

ts
const value = input ?? fallback;

@typescript-eslint/no-non-null-asserted-optional-chain &ZeroWidthSpace;

A non-null assertion after optional chaining usually indicates a boundary-design error.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong.; You should remove the non-null assertion.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const profile = user?.profile!;

Correct:

ts
const profile = user?.profile;

@typescript-eslint/no-non-null-assertion &ZeroWidthSpace;

Standard non-null assertions may express known runtime invariants; contradictory, redundant, and ineffective assertions remain checked.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Forbidden non-null assertion.; Consider using the optional chain operator '?.' instead. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const name = user!.name;

Correct:

ts
const name = user?.name ?? "Anonymous";

@typescript-eslint/no-redeclare &ZeroWidthSpace;

Uses the TypeScript rule to handle declaration merging and same-named type/value declarations correctly.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: '{{id}}' is already defined.; '{{id}}' is already defined as a built-in global variable.; '{{id}}' is already defined by a variable declaration.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
let value = 1;
let value = 2;

Correct:

ts
let value = 1;
value = 2;

@typescript-eslint/no-require-imports &ZeroWidthSpace;

Node configuration and scripts may need CommonJS; ESM-only import restrictions are disabled only for tool files.

  • Effective severity and scope: error: Vue SFC, UniApp NVue, Angular TypeScript
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue TSX, UniApp TSX, React TSX
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: A 'require()' style import is forbidden.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const path = require("node:path");

Correct:

ts
import path from "node:path";

@typescript-eslint/no-unnecessary-boolean-literal-compare &ZeroWidthSpace;

Removes boolean-literal comparisons that do not change the condition.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: This expression unnecessarily compares a nullable boolean value to false instead of using the ?? operator to provide a default.; This expression unnecessarily compares a nullable boolean value to true instead of using it directly.; This expression unnecessarily compares a nullable boolean value to true instead of negating it.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare const enabled: boolean;
if (enabled === true) start();

Correct:

ts
declare const enabled: boolean;
if (enabled) start();

@typescript-eslint/no-unnecessary-condition &ZeroWidthSpace;

Types may not fully represent external runtime inputs, so defensive conditions are allowed.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unnecessary conditional, value is always falsy.; This callback should return a conditional, but return is always falsy.; Unnecessary conditional, left-hand side of '??' operator is always 'null' or 'undefined'.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const ready = true;
if (ready) start();

Correct:

ts
const ready = true;
start();

@typescript-eslint/no-unnecessary-template-expression &ZeroWidthSpace;

Removes redundant template expressions without interpolation semantics.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Template literal expression is unnecessary and can be simplified.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const status = `${"ready"}`;

Correct:

ts
const status = "ready";

@typescript-eslint/no-unnecessary-type-arguments &ZeroWidthSpace;

Removes explicit type arguments inferable from call arguments.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: This is the default value for this type parameter, so it can be omitted.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare function createValue<T = string>(): T;
const value = createValue<string>();

Correct:

ts
declare function createValue<T = string>(): T;
const value = createValue();

@typescript-eslint/no-unnecessary-type-conversion &ZeroWidthSpace;

Disallows redundant conversions changing neither runtime values nor static types.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Remove the type conversion.; Instead, assert that the value satisfies the {{type}} type.; {{violation}} does not change the type or value of the {{type}}.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const enabled = Boolean(true);

Correct:

ts
const enabled = true;

@typescript-eslint/no-unused-expressions &ZeroWidthSpace;

Uses the TypeScript rule for assertion syntax; allows common short-circuit and conditional-expression calls.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Expected an assignment or function call and instead saw an expression.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
ready;

Correct:

ts
if (ready) start();

@typescript-eslint/no-unused-vars &ZeroWidthSpace;

defineEmits validators and framework callbacks may declare contract-only parameters; unused ordinary variables and imports still error.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Remove unused import declaration.; Remove unused variable "{{varName}}".; '{{varName}}' is {{action}} but never used{{additional}}.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const unused = loadData();

Correct:

ts
const data = loadData();
render(data);

@typescript-eslint/no-useless-default-assignment &ZeroWidthSpace;

Default parameters already provide fallback values; avoid redundant undefined arguments.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: This rule requires the 'strictNullChecks' compiler option to be turned on to function correctly.; Using '= undefined' to make a parameter optional adds unnecessary runtime logic. Use the '?' optional syntax instead.; Default value is useless because the {{ type }} is not optional.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface Options { limit: number }
declare const options: Options;
const { limit = 10 } = options;

Correct:

ts
interface Options { limit: number }
declare const options: Options;
const { limit } = options;

@typescript-eslint/prefer-nullish-coalescing &ZeroWidthSpace;

Primitive || and ?? expressions may have different business semantics and are not exchanged merely for style.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: This rule requires the 'strictNullChecks' compiler option to be turned on to function correctly.; Prefer using nullish coalescing operator ('??{{ equals }}') instead of an assignment expression, as it is simpler to read.; Prefer using nullish coalescing operator ('??{{ equals }}') instead of a logical {{ description }} ('||{{ equals }}'), as it is a safer operator.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface Config { timeout: number }
declare const input: Config | null;
declare const defaultConfig: Config;
const config = input || defaultConfig;

Correct:

ts
interface Config { timeout: number }
declare const input: Config | null;
declare const defaultConfig: Config;
const config = input ?? defaultConfig;

@typescript-eslint/prefer-optional-chain &ZeroWidthSpace;

Requires optional chaining only when the type includes null or undefined, preserving other falsy-value semantics.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Change to an optional chain.; Prefer using an optional chain expression instead, as it's more concise and easier to read.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface User { profile?: { name: string } }
declare const user: User | undefined;
const name = user && user.profile && user.profile.name;

Correct:

ts
interface User { profile?: { name: string } }
declare const user: User | undefined;
const name = user?.profile?.name;

@typescript-eslint/prefer-promise-reject-errors &ZeroWidthSpace;

Allows transparent forwarding of unknown external Promise rejection reasons; statically known strings, numbers, and similar values are still reported.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Expected the Promise rejection reason to be an Error.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
function fail(): Promise<never> { return Promise.reject("Failed"); }

Correct:

ts
function fail(): Promise<never> { return Promise.reject(new Error("Failed")); }

@typescript-eslint/prefer-readonly &ZeroWidthSpace;

Private members assigned only during construction should be readonly.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Member '{{name}}' is never reassigned; mark it as 'readonly'.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
class User { private id: number; constructor(id: number) { this.id = id; } getId(): number { return this.id; } }

Correct:

ts
class User { private readonly id: number; constructor(id: number) { this.id = id; } getId(): number { return this.id; } }

@typescript-eslint/prefer-regexp-exec &ZeroWidthSpace;

Does not require RegExp.exec instead of string matching APIs.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Use the 'RegExp#exec()' method instead.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare const text: string;
const match = text.match(/fast/);

Correct:

ts
declare const text: string;
const match = /fast/.exec(text);

Getters and setters must use compatible types.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: 'get()' type should be assignable to its equivalent 'set()' type.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
class User { get name(): string { return "Fast"; } set name(value: number) { save(value); } }

Correct:

ts
class User { get name(): string { return "Fast"; } set name(value: string) { save(value); } }

@typescript-eslint/require-await &ZeroWidthSpace;

Async without await changes return and exception semantics; remove async or return a real Promise.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: {{name}} has no 'await' expression.; Remove 'async'.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
async function getValue(): Promise<number> { return 1; }

Correct:

ts
function getValue(): number { return 1; }

@typescript-eslint/restrict-template-expressions &ZeroWidthSpace;

Numbers and booleans are safe common template interpolations; objects, any, and nullish values need explicit handling.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Invalid type "{{type}}" of template literal expression.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface User { name: string }
declare const user: User;
const label = `User: ${user}`;

Correct:

ts
interface User { name: string }
declare const user: User;
const label = `User: ${user.name}`;

@typescript-eslint/return-await &ZeroWidthSpace;

Requires return await only where error semantics need it, avoiding style-only awaits.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Returning an awaited promise is not allowed in this context.; Remove 'await' before the expression. Use caution as this may impact control flow.; Returning an awaited value that is not a promise is not allowed.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
interface User { id: number }
declare function fetchUser(): Promise<User>;
async function load(): Promise<User> { try { return fetchUser(); } catch (error) { recover(error); throw error; } }

Correct:

ts
interface User { id: number }
declare function fetchUser(): Promise<User>;
async function load(): Promise<User> { try { return await fetchUser(); } catch (error) { recover(error); throw error; } }

@typescript-eslint/strict-void-return &ZeroWidthSpace;

Does not restrict framework lifecycle or event callback return styles.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Async function used in a context where a void function is expected.; Value-returning function used in a context where a void function is expected.; Value returned in a context where a void return is expected.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
const callback: () => void = () => 42;

Correct:

ts
const callback: () => void = () => { log(); };

@typescript-eslint/switch-exhaustiveness-check &ZeroWidthSpace;

Vue SFCs may handle nonexhaustive unions/enums through templates and runtime fallbacks.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue TSX, UniApp TSX, React TSX, Angular TypeScript
  • Disabled in: Vue SFC, UniApp NVue
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Add branches for missing cases.; The switch statement is exhaustive, so the default case is unnecessary.; Switch is not exhaustive. Cases not matched: {{missingBranches}}
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
type State = "idle" | "ready";
declare const state: State;
switch (state) { case "idle": break; }

Correct:

ts
type State = "idle" | "ready";
declare const state: State;
switch (state) { case "idle": break; case "ready": break; }

@typescript-eslint/unified-signatures &ZeroWidthSpace;

Public overloads affect type queries and call contracts; do not merge them merely to reduce lines.

  • Effective severity and scope: disabled by default through an explicit local override
  • Disabled in: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: {{failureStringStart}} with identical parameters.; {{failureStringStart}} with a rest parameter.; {{failureStringStart}} with an optional parameter.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
function format(value: string): string;
function format(value: number): string;

Correct:

ts
function format(value: string | number): string;

@typescript-eslint/use-unknown-in-catch-callback-variable &ZeroWidthSpace;

Promise catch callbacks receive unknown rejection reasons; use unknown and narrow explicitly.

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Add an explicit ': [unknown]' type annotation to the rejection callback rest variable.; Add an explicit ': unknown' type annotation to the rejection callback variable.; Prefer the safe ': unknown' for a '{{method}}'{{append}} callback variable.
  • Example type: Direct code example for an explicit repository rule

Incorrect:

ts
declare const promise: Promise<void>;
promise.catch((error: any) => report(error));

Correct:

ts
declare const promise: Promise<void>;
promise.catch((error: unknown) => report(normalizeError(error)));

Rules from third-party presets (32 rules) &ZeroWidthSpace;

@typescript-eslint/await-thenable &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Disallow awaiting a value that is not a Thenable

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unexpected 'await' of a non-Promise (non-"Thenable") value.; Unexpected 'await using' of a value that is not async disposable.; Convert to an ordinary 'for...of' loop.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
const value = await 42;

Correct:

ts
const value = await Promise.resolve(42);

@typescript-eslint/ban-ts-comment &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Disallow @ts-<directive> comments or require descriptions after directives

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Replace "@ts-ignore" with "@ts-expect-error".; Do not use "@ts-{{directive}}" because it alters compilation errors.; The description for the "@ts-{{directive}}" directive must match the {{format}} format.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
// @ts-ignore
const count: number = loadValue();

Correct:

ts
// @ts-expect-error -- legacy API returns an invalid declaration
const count: number = loadValue();

@typescript-eslint/no-array-constructor &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow generic Array constructors

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: The array literal notation [] is preferable.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
const values = new Array();

Correct:

ts
const values: unknown[] = [];

@typescript-eslint/no-array-delete &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow using the delete operator on array values

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Using the 'delete' operator with an array expression is unsafe.; Use 'array.splice()' instead.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const items: string[];
delete items[index];

Correct:

ts
declare const items: string[];
items.splice(index, 1);

@typescript-eslint/no-base-to-string &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Require .toString() and .toLocaleString() to only be called on objects which provide useful information when stringified

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Using 'join()' for {{name}} {{certainty}} use Object's default stringification format ('[object Object]') when stringified.; '{{name}}' {{certainty}} use Object's default stringification format ('[object Object]') when stringified.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
interface User { name: string }
declare const user: User;
const label = `User: ${user}`;

Correct:

ts
interface User { name: string }
declare const user: User;
const label = `User: ${user.name}`;

@typescript-eslint/no-duplicate-enum-values &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow duplicate enum member values

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Duplicate enum member value {{value}}.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
enum Status { Ready = 1, Done = 1 }

Correct:

ts
enum Status { Ready = 1, Done = 2 }

@typescript-eslint/no-duplicate-type-constituents &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow duplicate constituents of union or intersection types

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: {{type}} type constituent is duplicated with {{previous}}.; Explicit undefined is unnecessary on an optional parameter.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
type Id = string | string;

Correct:

ts
type Id = string | number;

@typescript-eslint/no-empty-object-type &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow accidentally using the "empty object" type

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: `An empty interface declaration allows any non-nullish value, including literals like '0' and '""'.
  • If that's what you want, disable this lint rule with an inline comment or configure the '' rule option.
  • If you want a type meaning "any object", you probably want 'object' instead.
  • If you want a type meaning "any value", you probably want 'unknown' instead.; An interface declaring no members is equivalent to its supertype.; The '{}' ("empty object") type allows any non-nullish value, including literals like '0' and '""'.
  • If that's what you want, disable this lint rule with an inline comment or configure the '' rule option.
  • If you want a type meaning "any object", you probably want 'object' instead.
  • If you want a type meaning "any value", you probably want 'unknown' instead.`
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
type Empty = {};

Correct:

ts
type Empty = Record<string, never>;

@typescript-eslint/no-extra-non-null-assertion &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow extra non-null assertions

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Forbidden extra non-null assertion.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
const name = user!!.name;

Correct:

ts
const name = user!.name;

@typescript-eslint/no-for-in-array &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow iterating over an array with a for-in loop

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: For-in loops over arrays skips holes, returns indices as strings, and may visit the prototype chain or other enumerable properties. Use a more robust iteration method such as for-of or array.forEach instead.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const items: readonly string[];
for (const index in items) use(items[index]);

Correct:

ts
declare const items: readonly string[];
for (const item of items) use(item);

@typescript-eslint/no-implied-eval &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow the use of eval()-like functions

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Implied eval. Do not use the Function constructor to create functions.; Implied eval. Consider passing a function.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
setTimeout("refresh()", 1000);

Correct:

ts
setTimeout(() => refresh(), 1000);

@typescript-eslint/no-misused-new &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Enforce valid definition of new and constructor

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Class cannot have method named 'new'.; Interfaces cannot be constructed, only classes.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
interface User { new (): User; }

Correct:

ts
interface UserConstructor { new (): User; }

@typescript-eslint/no-redundant-type-constituents &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow members of unions and intersections that do nothing or override type information

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: '{{typeName}}' is an 'error' type that acts as 'any' and overrides all other types in this {{container}} type.; {{literal}} is overridden by {{primitive}} in this union type.; '{{typeName}}' is overridden by other types in this {{container}} type.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
type Name = string | "Fast";

Correct:

ts
type Name = string;

@typescript-eslint/no-this-alias &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow aliasing this

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unexpected aliasing of 'this' to local variable.; Unexpected aliasing of members of 'this' to local variables.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
const self = this;
self.save();

Correct:

ts
this.save();

@typescript-eslint/no-unnecessary-type-assertion &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow type assertions that do not change the type of an expression

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: This assertion is unnecessary since the receiver accepts the original type of the expression.; This assertion is unnecessary since it does not change the type of the expression.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const name: string;
const normalized = name as string;

Correct:

ts
declare const name: string;
const normalized = name;

@typescript-eslint/no-unnecessary-type-constraint &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow unnecessary constraints on generic types

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Remove the unnecessary '{{constraint}}' constraint.; Constraining the generic type '{{name}}' to '{{constraint}}' does nothing and is unnecessary.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
function identity<T extends unknown>(value: T): T { return value; }

Correct:

ts
function identity<T>(value: T): T { return value; }

@typescript-eslint/no-unsafe-argument &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow calling a function with a value with type any

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unsafe argument of type {{sender}} assigned to a parameter of type {{receiver}}.; Unsafe spread of an {{sender}} array type.; Unsafe spread of an {{sender}} type.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
interface User { id: number }
declare function saveUser(user: User): void;
declare const input: any;
saveUser(input);

Correct:

ts
interface User { id: number }
declare function isUser(value: unknown): value is User;
declare function saveUser(user: User): void;
declare const input: unknown;
if (isUser(input)) saveUser(input);

@typescript-eslint/no-unsafe-assignment &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow assigning a value with type any to variables and properties

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unsafe assignment of an {{sender}} value.; Unsafe assignment of an {{sender}} value. 'this' is typed as 'any'. You can try to fix this by turning on the 'noImplicitThis' compiler option, or adding a 'this' parameter to the function.; Unsafe array destructuring of an {{sender}} array value.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const input: any;
const user = input;

Correct:

ts
interface User { id: number }
declare function parseUser(value: unknown): User;
declare const input: unknown;
const user = parseUser(input);

@typescript-eslint/no-unsafe-call &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow calling a value with type any

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unsafe call of a type that could not be resolved.; Unsafe call of a 'this' type that could not be resolved.; Unsafe construction of a type that could not be resolved.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const callback: any;
callback();

Correct:

ts
declare const callback: () => void;
callback();

@typescript-eslint/no-unsafe-declaration-merging &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow unsafe declaration merging

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unsafe declaration merging between classes and interfaces.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
interface User { id: number }
class User {}

Correct:

ts
interface UserData { id: number }
class User {}

@typescript-eslint/no-unsafe-enum-comparison &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow comparing an enum value with a non-enum value

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: The case statement does not have a shared enum type with the switch predicate.; The two values in this comparison do not have a shared enum type.; Replace with an enum value comparison.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
enum Status { Ready = "ready" }
declare const status: Status;
if (status === "ready") start();

Correct:

ts
enum Status { Ready = "ready" }
declare const status: Status;
if (status === Status.Ready) start();

@typescript-eslint/no-unsafe-function-type &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow using the unsafe built-in Function type

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: The 'Function' type accepts any function-like value. Prefer explicitly defining any function parameters and return type.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
let callback: Function;

Correct:

ts
let callback: (...args: unknown[]) => unknown;

@typescript-eslint/no-unsafe-member-access &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow member access on a value with type any

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: The type of computed name {{property}} cannot be resolved.; Unsafe member access {{property}} on a type that cannot be resolved.; Unsafe member access {{property}}. The type of 'this' cannot be resolved. You can try to fix this by turning on the 'noImplicitThis' compiler option, or adding a 'this' parameter to the function.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const input: any;
const id = input.id;

Correct:

ts
interface User { id: number }
declare function isUser(value: unknown): value is User;
declare const input: unknown;
const id = isUser(input) ? input.id : undefined;

@typescript-eslint/no-unsafe-return &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow returning a value with type any from a function

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Unsafe return of a value of type {{type}}.; Unsafe return of type '{{sender}}' from function with return type '{{receiver}}'.; Unsafe return of a value of type '{{type}}'. 'this' is typed as 'any'. You can try to fix this by turning on the 'noImplicitThis' compiler option, or adding a 'this' parameter to the function.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
interface User { id: number }
declare const input: any;
function load(): User { return input; }

Correct:

ts
interface User { id: number }
declare function parseUser(value: unknown): User;
declare const input: unknown;
function load(): User { return parseUser(input); }

@typescript-eslint/no-unsafe-unary-minus &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Require unary negation to take a number

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Argument of unary negation should be assignable to number | bigint but is {{type}} instead.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const value: string;
const result = -value;

Correct:

ts
declare const value: number;
const result = -value;

@typescript-eslint/no-wrapper-object-types &ZeroWidthSpace;

Disallows unsafe, invalid, or misleading constructs. Upstream description: Disallow using confusing built-in primitive class wrappers

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Prefer using the primitive '{{preferred}}' as a type name, rather than the upper-cased '{{typeName}}'.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
const name: String = "Fast";

Correct:

ts
const name: string = "Fast";

@typescript-eslint/only-throw-error &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Disallow throwing non-Error values as exceptions

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Expected an error object to be thrown.; Do not throw undefined.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
throw "Failed";

Correct:

ts
throw new Error("Failed");

@typescript-eslint/prefer-as-const &ZeroWidthSpace;

Prefers the modern or clearer form specified by this rule. Upstream description: Enforce the use of as const over literal type

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Expected a 'const' instead of a literal type assertion.; Expected a 'const' assertion instead of a literal type annotation.; You should use 'as const' instead of type annotation.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
let status: "ready" = "ready";

Correct:

ts
let status = "ready" as const;

@typescript-eslint/prefer-namespace-keyword &ZeroWidthSpace;

Prefers the modern or clearer form specified by this rule. Upstream description: Require using namespace keyword over module keyword to declare custom TypeScript modules

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Supported; review semantics and the diff before applying
  • Rule source: Official documentation
  • Common messages: Use 'namespace' instead of 'module' to declare custom TypeScript modules.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
module Format { export const trim = String.prototype.trim; }

Correct:

ts
namespace Format { export const trim = String.prototype.trim; }

@typescript-eslint/restrict-plus-operands &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Require both operands of addition to be the same type and be bigint, number, or string

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Numeric '+' operations must either be both bigints or both numbers. Got '{{left}}' + '{{right}}'.; Invalid operand for a '+' operation. Operands must each be a number or {{stringLike}}. Got '{{type}}'.; Operands of '+' operations must be a number or {{stringLike}}. Got '{{left}}' + '{{right}}'.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
declare const count: number;
declare const offset: bigint;
const total = count + offset;

Correct:

ts
declare const count: number;
declare const offset: number;
const total = count + offset;

@typescript-eslint/triple-slash-reference &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Disallow certain triple slash directives in favor of ES6-style import declarations

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: Do not use a triple slash reference for {{module}}, use 'import' style instead.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
/// <reference path="./types.d.ts" />
const user: User = loadUser();

Correct:

ts
import type { User } from "./types";
const user: User = loadUser();

@typescript-eslint/unbound-method &ZeroWidthSpace;

Checks the corresponding code constraint. Upstream description: Enforce unbound methods are called with their expected scope

  • Effective severity and scope: error: TypeScript base, Framework-neutral TSX, Vue SFC, Vue TSX, UniApp NVue, UniApp TSX, React TSX, Angular TypeScript
  • Autofix: Unsupported or not declared upstream
  • Rule source: Official documentation
  • Common messages: A method that is not declared with 'this: void' may cause unintentional scoping of 'this' when separated from its object. Consider using an arrow function or explicitly '.bind()'ing the method to avoid calling the method with an unintended 'this' value. ; A method that is not declared with 'this: void' may cause unintentional scoping of 'this' when separated from its object. Consider using an arrow function or explicitly '.bind()'ing the method to avoid calling the method with an unintended 'this' value. If a function does not access 'this', it can be annotated with 'this: void'.
  • Example type: Direct code example for a third-party preset rule

Incorrect:

ts
class Logger { prefix = "Fast"; log(message: string): void { console.log(this.prefix, message); } }
const logger = new Logger();
const log = logger.log;
log("Saved");

Correct:

ts
class Logger { prefix = "Fast"; log(message: string): void { console.log(this.prefix, message); } }
const logger = new Logger();
const log = logger.log.bind(logger);
log("Saved");