Course contentsShow
← TypeScript
Lesson 1190 of 1,79628. tsconfig in DepthFree lesson

The Cost of strict: False Positives

Common patterns that strict mode flags incorrectly, and when suppressions are justified.

The Cost of strict: False Positives

You'll learn: Why TypeScript's strict mode sometimes flags perfectly safe code, and when it's reasonable to work around these limitations.

The Reality of Over-Cautious Checking

TypeScript's strict mode is designed to catch real bugs, but it's not perfect. Sometimes it raises errors for code that would work fine at runtime. These false positives happen because TypeScript's type system is intentionally conservative—it prefers to warn you about possible problems rather than miss real ones.

Think of it like a smoke detector that occasionally goes off when you're just cooking. It's annoying, but you'd rather have a sensitive detector than one that misses actual fires.

Common False Positive Patterns

Object property existence checks: You might know a property exists after checking it, but TypeScript can't always track that through complex control flow or after passing objects to functions.

Initialized-in-helper patterns: Class properties initialized through a helper method may trigger strictPropertyInitialization errors, even though they're definitely assigned before use.

Array manipulation assumptions: After filtering an array, you know certain properties exist on remaining elements, but TypeScript may not narrow the type accordingly.

Third-party library quirks: Well-typed libraries sometimes have edge cases where their types are overly restrictive for valid use cases.

When Suppressions Are Justified

Suppressions (like // @ts-expect-error or the ! non-null assertion) are acceptable when:

  • You've verified the runtime behavior is safe
  • The TypeScript limitation is well-understood
  • You've documented why the suppression is needed
  • Refactoring the code would significantly harm readability

The key is intentionality—suppress knowingly, not lazily.

Key Takeaway: Strict mode occasionally produces false positives because TypeScript prioritizes safety over convenience. Justified suppressions are a pragmatic response, not a failure—just document your reasoning.