Ban TypeScript Suppression Comments

ID

javascript.ts_ban_ts_comment

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

JavaScript

Tags

suppression, typescript

Description

Reports TypeScript directive comments — @ts-ignore, @ts-nocheck, @ts-expect-error and @ts-check — that suppress or alter compiler errors. Each one mutes a real type signal that future maintainers will likely never revisit, masking bugs and accumulating type debt.

@ts-expect-error is the least-bad of the four because it fails when the suppressed error disappears (so it self-removes when the underlying issue is fixed); the rule still flags it so the team has the choice to keep it intentionally with a written justification, rather than letting it pile up by accident.

Rationale

// Bad — silences a legitimate type error.
// @ts-ignore
const a: number = "string";

// @ts-nocheck
const b: number = "another";   // entire file becomes unchecked

// @ts-expect-error wrong type by design
const c: number = false;

@ts-ignore and @ts-nocheck make any subsequent type drift invisible. @ts-expect-error is at least self-correcting, but it is still worth a deliberate decision rather than a default reflex.

Remediation

Fix the underlying type problem so the directive can be removed. When the type is genuinely beyond the local scope to fix:

  • Use unknown and narrow inside the function.

  • Introduce a precise type alias and assert against it once at the boundary.

  • For a deliberate expect-error, write a comment explaining why the error is expected, and pair it with a tracking issue.

// Good — fix at the boundary, narrow inside.
function parsePort(value: unknown): number {
  if (typeof value === "string") return parseInt(value, 10);
  if (typeof value === "number") return value;
  throw new TypeError(`port: ${typeof value}`);
}