← Back to archive

Stdle #77 · narrowing · 2026-08-22

What does this TypeScript snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

type T = { t: "x" } | { t: "y" }
function f(v: T): string {
switch (v.t) {
case "x": return "X"
case "y": return "Y"
}
}
console.log(f({ t: "y" }))
Narrowing
4 attempts left

Answer & explanation