Skip to content

    ↑↓ move · ⏎ open · esc close

    TS2367

    Comparison with no overlap

    This comparison appears to be unintentional because the types 'string' and 'number' have no overlap.

    The compiler’s own words. Not translated — this is the string you pasted into a search box.

    The two sides can never be equal, so the comparison is always false and the compiler assumes you did not mean to write it.

    Reproduction

    declare const a: string
    
    if (a === 1) {
    }

    The build asserts this emits exactly this code.

    Why the compiler says this

    This is one of the few diagnostics that is about intent rather than safety — the comparison would run perfectly well and return `false` forever. It fires most usefully after a refactor, when a variable that used to be a union has been narrowed and a branch that once mattered has quietly become dead code. Treat it as a note that something upstream changed.

    Fixes

    1. 01
      declare const a: string
      
      if (a === '1') {
      }

      Compare against the type you actually have.

    2. 02
      declare const a: string | number
      
      if (a === 1) {
      }

      Or widen the variable, if it really can be either. Then the comparison has a purpose again and narrows `a` to `number` inside the block.

    Takeaway

    A comparison the compiler calls pointless is usually a branch that used to be reachable. Delete it or fix the type it was guarding — do not cast to keep it.

    Where to go next

    Errors