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

Given this exhaustive switch, what is the purpose of the `never` assignment in the `default` branch?

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; } }