TypeScript Type System: Deep Cuts
Narrowing you can trust, the any/unknown/never/void lattice, structural-typing surprises, and literal widening with as const & satisfies. Every explanation compiles the snippet so a wrong answer becomes a lesson.
Questions
- Not answered. After this
typeofguard, what is the type ofx? - Not answered. Which guard narrows
Fish | Birdby checking for a property? - Not answered. Why is
valstillunknowninside theif? - Not answered. Why does
token.lengtherror inside the listener? - Not answered. What forces a compile error when a new union member is forgotten?
- Not answered. Which line fails to compile?
- Not answered. Which type is the type-safe top type of TypeScript?
- Not answered. Does this compile?
- Not answered. Is the assignment to
namea type error? - Not answered. Reduce the intersection: what single type is
string & number? - Not answered. Where does
never(notany) silently show up? - Not answered. Which assignment errors on the extra
zproperty? - Not answered. Does
const p: Point = v;compile? - Not answered. Why does a one-argument callback satisfy
map? - Not answered. Why does
getUser(raw)fail butgetUser(raw as UserId)succeed? - Not answered. What is the type of
config.mode? - Not answered. What are the inferred types of
aandb? - Not answered. What is the type of
pair? - Not answered. Which keeps the precise inferred type and validates against the constraint?
- Not answered. Which assertion makes
[3, 4]infer as a readonly tuplereadonly [3, 4]?