Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumTypeScriptdiscriminated unionsSingle-choice MCQ

Why does the `default` branch compile without error, and what would break it?

type Shape = | { kind: "circle"; r: number } | { kind: "square"; s: number }; function area(sh: Shape): number { switch (sh.kind) { case "circle": return Math.PI * sh.r ** 2; case "square": return sh.s ** 2; default: const _exhaustive: never = sh; return _exhaustive; } }