What Are Type Suppression Comments
You'll learn: How to use special comments to intentionally disable TypeScript's type checking when you truly need an escape hatch.
The Concept
Sometimes you're working with TypeScript and you know there's a type error, but you have a legitimate reason to ignore it—maybe you're dealing with legacy code, a poorly-typed third-party library, or you're in the middle of a large refactoring. Type suppression comments are special directives you can add to your code that tell the TypeScript compiler: "I see this error, but trust me, skip it."
Think of them like a "skip this question" button on a test—it's there for emergencies, but using it too often defeats the purpose of taking the test.
The Three Main Comments
TypeScript provides three suppression comments:
@ts-ignore
This comment tells TypeScript to ignore any error on the very next line:
// @ts-ignore
const result = someUntypedFunction();
It's the bluntest tool—it silences everything on that line, whether there's actually an error or not.
@ts-expect-error
This is the safer alternative. It tells TypeScript: "I expect an error on the next line, and I'm intentionally ignoring it":
// @ts-expect-error
const invalid: string = 42;
The key difference: if TypeScript doesn't find an error, @ts-expect-error itself produces an error. This prevents suppression comments from becoming stale when code is fixed later.
@ts-nocheck
This comment goes at the very top of a file and disables type checking for the entire file:
// @ts-nocheck
// Everything in this file is now unchecked
It's useful during gradual migration from JavaScript, but it's the nuclear option.
When to Use Them
- Temporary workarounds during refactoring
- Known issues with third-party types you can't fix
- Gradual migration from JavaScript (especially
@ts-nocheck) - Test files where you're intentionally checking invalid states
The Golden Rule
Type suppression comments are escape hatches, not standard practice. Every time you use one, you're accepting the risk of runtime errors. Prefer @ts-expect-error over @ts-ignore because it documents that you're aware of the problem and prevents the comment from lingering after the issue is resolved.
Key Takeaway: Type suppression comments (@ts-ignore, @ts-expect-error, @ts-nocheck) let you intentionally disable type checking—use them sparingly as escape hatches, and prefer @ts-expect-error for safety.