A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-77.ts
1typeT={t:"x"}|{t:"y"}
2functionf(v:T):string{
3switch(v.t){
4case"x":return"X"
5case"y":return"Y"
6}
7}
8console.log(f({t:"y"}))
Narrowing
Answer & explanation
Console output
Y
Why
Because every member of the union is handled, TypeScript considers the switch exhaustive and accepts the function with no default, even though there is no explicit return after the switch. At runtime `v.t` is "y", so the "y" case returns "Y". Exhaustiveness is a type-level property; the runtime simply matches the case.