• Error
  • Reported by the type checker

TS2678

Type '{0}' is not comparable to type '{1}'.

A switch case value can never equal the switch expression because their types don't overlap. Fix the case value or the type.

What it means

The checker compares each case value with the switch expression. When their types have no values in common, that case can never match.

Example

index.ts
function f(kind: "a" | "b") {
  switch (kind) {
    case "c":
      break;
  }
}
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(3,10): error TS2678: Type '"c"' is not comparable to type '"a" | "b"'.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Correct the case value (often a typo or a stale value).
  • If the value can really occur, add it to the switched value's type.