Which fix removes the bug?
type Shape = { kind: 'circle'; r: number } | { kind: 'square'; s: number };
function area(x: Shape): number {
if (x.kind === 'circle') return Math.PI * x.r ** 2;
}
- Handle the square branch
- Widen kind to a string
- Mark r as optional
- Return any from area
Squares fall through and return undefined; an exhaustive switch with a
Play Problem Solving ▸
never check catches this.