Skip to content
Latchkey

tsc TS2367: This comparison appears to be unintentional in CI

TS2367 flags a comparison between two types that can never be equal, so the condition is always false. It often surfaces a typo in a string literal union or a stale enum comparison.

What this error means

tsc fails with "error TS2367: This comparison appears to be unintentional because the types 'A' and 'B' have no overlap." at an === or !== comparison.

tsc
src/state.ts:4:7 - error TS2367: This comparison appears to be unintentional because the types
'"open" | "closed"' and '"opened"' have no overlap.

4   if (status === 'opened') {
        ~~~~~~~~~~~~~~~~~~~

Common causes

A literal compared against a value outside its union

The variable is a string-literal union, and the comparison uses a literal (a typo) that is not a member of that union, so they never overlap.

A stale enum or narrowed type comparison

After narrowing, the value can no longer equal the compared constant, so tsc reports the comparison as always-false.

How to fix it

Compare against a valid member

  1. Read the two types tsc says have no overlap.
  2. Fix the literal typo so it is a real member of the union.
  3. Re-run tsc to confirm the comparison can be true.
src/state.ts
if (status === 'closed') { /* ... */ }

Widen the type if both values are legitimate

If the compared value really can occur, broaden the variable type to include it rather than casting.

src/state.ts
type Status = 'open' | 'closed' | 'opened';

How to prevent it

  • Use string-literal unions and enums so typos in comparisons are caught.
  • Let the editor autocomplete literal values.
  • Run tsc in strict mode so always-false comparisons surface.

Frequently asked questions

What causes "TS2367 "comparison appears to be unintentional""?
The variable is a string-literal union, and the comparison uses a literal (a typo) that is not a member of that union, so they never overlap.
How do I fix TS2367 "comparison appears to be unintentional"?
Compare against a valid member

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card