@ts-ignore vs @ts-expect-error
You'll learn the critical difference between two type suppression comments and why one is safer than the other.
The Problem with Silent Suppression
Both @ts-ignore and @ts-expect-error tell TypeScript to suppress type errors on the next line. They're your escape hatch when you truly need to bypass the compiler. But they work very differently.
@ts-ignore is the dangerous one. It silently suppresses any error on the next line, no questions asked. The problem? If you fix the underlying issue or if there was never an error to begin with, @ts-ignore stays silent. It becomes dead weight in your codebase.
@ts-expect-error is the safer alternative. It also suppresses an error on the next line, but here's the key: if there's no error to suppress, TypeScript fails compilation. This means it's self-documenting and self-cleaning.
The Difference in Practice
let value: string = "hello";
// @ts-ignore
value = 42; // Suppresses the error silently
// If you later fix the type...
let betterValue: string | number = "hello";
// @ts-ignore
betterValue = 42; // Still here, but now pointless. TypeScript says nothing.
With @ts-expect-error:
let value: string = "hello";
// @ts-expect-error: Temporary workaround for migration
value = 42; // Suppresses the error
// After fixing the type...
let betterValue: string | number = "hello";
// @ts-expect-error
betterValue = 42; // ❌ TypeScript error: Expected an error but none found
When to Choose Which
Use @ts-expect-error when:
- You're temporarily suppressing a known error during refactoring
- You want the comment to become invalid once the code is fixed
- You're documenting technical debt that should be resolved
Avoid @ts-ignore in almost all cases. It creates invisible problems that persist even after the original issue is resolved.
Key Takeaway: @ts-expect-error is self-validating — it fails if there's no error to suppress, preventing outdated suppressions from accumulating in your codebase. Always prefer it over @ts-ignore.