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

When @ts-expect-error Is Preferred

Using @ts-expect-error for known issues you plan to fix, making it clear when the error is resolved.

When @ts-expect-error Is Preferred

You'll learn: When to choose @ts-expect-error over @ts-ignore to document known issues you intend to fix.

The Strategic Choice for Temporary Problems

While both @ts-ignore and @ts-expect-error suppress TypeScript errors, they communicate very different intentions to your team and future self.

Use @ts-expect-error when you know there's a type error and you're deliberately marking it as a known issue you plan to address. Think of it like putting a sticky note that says "Fix this before shipping" versus one that says "Ignore forever."

Why @ts-expect-error Shines

The magic of @ts-expect-error is that it fails when the error disappears. If you fix the underlying type issue (or TypeScript updates and the error goes away), @ts-expect-error will produce a compiler error saying the suppression is no longer needed.

This creates a self-cleaning mechanism: your temporary workarounds don't silently become permanent technical debt.

// During migration: third-party lib has wrong types
// @ts-expect-error - Known issue, lib types outdated
const config = externalLib.getConfig(123);

// Later, if the library fixes its types, TypeScript will complain:
// "Unused '@ts-expect-error' directive"

Common Scenarios

Temporary third-party type bugs: When a library has incorrect types but you need to ship today.

Mid-migration boundaries: When converting a large codebase from JavaScript, marking areas you'll fix in the next sprint.

Known regression testing: When you've identified a type issue but need to deploy a hotfix first.

Deprecated API bridges: When supporting old code paths you're actively removing.

The Communication Benefit

@ts-expect-error signals to code reviewers: "I see this, I know it's wrong, there's a plan." It makes your technical debt visible and trackable, unlike @ts-ignore which suggests "don't ask questions."

Key Takeaway: Use @ts-expect-error for known issues you plan to fix—it alerts you when the problem is resolved, preventing obsolete suppressions from cluttering your codebase.