Code QuizAdvanced

Exhaustiveness Check Misses a Case

A never-based exhaustiveness check errors because one union member is unhandled.

Codetypescript
type Shape =
  | { kind: "circle" }
  | { kind: "square" }
  | { kind: "triangle" };

function handle(shape: Shape): number {
  switch (shape.kind) {
    case "circle": return 1;
    case "square": return 2;
    default:
      const _exhaustive: never = shape;
      return _exhaustive;
  }
}

Why does `const _exhaustive: never = shape;` fail to compile?

Watch the code walkthrough

Watch on YouTube →