A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-102.ts
1functionisStr(x:unknown):xisstring{
2returntypeofx==="string"
3}
4console.log(isStr(42))
Narrowing
Answer & explanation
Console output
false
Why
A user-defined type predicate `x is string` is only a compile-time annotation on the return type; the function still runs its real body. Here the body checks `typeof x === "string"`, which is false for 42. The predicate would narrow the caller`s type only when this boolean is true.