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

Inside the `if` branch, can you safely read `sh.r`, and why?

type Circle = { kind: "shape"; r: number }; type Square = { kind: "shape"; s: number }; type Shape = Circle | Square; function area(sh: Shape) { if (sh.kind === "shape") { return sh.r; } }