Course contentsShow
← TypeScript
Lesson 901 of 1,79620. The any Escape HatchFree lesson

Linting Suppression Comments

Using ESLint rules to flag or limit suppression comments, ensuring they're reviewed and justified in code review.

Linting Suppression Comments

What you'll learn: How to use ESLint rules to automatically flag, limit, and enforce review of type-suppression comments, ensuring they don't slip through without justification.

The Problem with Invisible Suppressions

You've learned how to use @ts-ignore and @ts-expect-error to suppress type errors when absolutely necessary. But here's the danger: these comments are invisible at runtime and easy to forget. Worse, they can accumulate silently across a codebase, each one representing a small hole in your type safety.

This is where ESLint comes in as your safety net.

ESLint Rules for Suppression Comments

ESLint provides rules specifically designed to catch and regulate suppression comments:

@typescript-eslint/ban-ts-comment

This rule flags or restricts the use of TypeScript suppression comments. You can configure it to:

  • Forbid certain patterns entirely (e.g., ban @ts-ignore while allowing @ts-expect-error)
  • Require descriptions alongside suppressions
  • Set minimum description lengths to ensure meaningful explanations
{
  "rules": {
    "@typescript-eslint/ban-ts-comment": [
      "error",
      {
        "ts-expect-error": "allow-with-description",
        "ts-ignore": true,
        "minimumDescriptionLength": 10
      }
    ]
  }
}

This configuration bans @ts-ignore completely, but allows @ts-expect-error only when followed by a description of at least 10 characters.

Why This Matters in Code Review

Think of linting rules as automated code reviewers that never get tired. They ensure:

  • Every suppression has a documented reason that reviewers can evaluate
  • Suppressions stand out in pull requests rather than hiding silently
  • Teams enforce consistent standards for when suppressions are acceptable
  • Future maintainers understand context without archaeological code digging

Without these rules, a developer might write @ts-ignore in a hurry, get their code working, and move on—leaving a permanent blind spot in your type safety.

Key Takeaway: Use ESLint rules like @typescript-eslint/ban-ts-comment to automatically enforce that every type suppression comment is visible, justified, and documented—turning suppressions from silent technical debt into explicit, reviewable decisions.