TypeScriptintermediate
Discriminated unions with an exhaustive switch and a never check
type Shape =
| { kind: "circle"; radius: number }
| { kind: "square"; side: number }
| { kind: "rectangle"; width: number; height: number };
Make adding a new union case a compile error, not a silent runtime bug, using a switch that assigns the leftover case to never.