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

Why does TypeScript reject the read of `s.value` inside the `if`, even though both narrowed members have a `value` property?

type Box = | { tag: "num"; value: number } | { tag: "str"; value: string } | { tag: "none" }; function read(s: Box) { if (s.tag !== "none") { return s.value.toFixed(2); } }