🔮 Output PredictionTS TypeScript Hard⚡+35 XP
Discriminated Union
How does TypeScript narrow this union?
TypeScript
type Shape = { kind: "circle"; r: number } | { kind: "square"; side: number };
function area(s: Shape) {
if (s.kind === "circle") return Math.PI * s.r ** 2;
}