A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-79.ts
1typeA={kind:"a";x:number}
2typeB={kind:"b";y:number}
3functionf(v:A|B){return"x"inv}
4console.log(f({kind:"b",y:2}))
Narrowing
Answer & explanation
Console output
false
Why
TypeScript uses `"x" in v` to narrow the union to branch A, but the function still returns the literal runtime result of the `in` check. The object passed is the B shape `{ kind, y }`, which has no `x` key, so `in` returns false. The compile-time narrowing and the runtime boolean are two separate things.