TypeScript
TypeScript's type system as it really works: structural typing, unknown and never, narrowing, generics, utility types, and why types vanish at runtime.
6 lessons
Type system core
- 1Structural typing, interfaces and declaration mergingThe compiler asks what a value has, never what it is called; fresh literals, merging and satisfies are the rules around that.
- 2any vs unknown vs neverany stops the checking and spreads; unknown lets anything in and nothing out unchecked; never has no values, so a leftover becomes an error.
- 3Narrowing and discriminated unionsA check narrows a union to the members that pass; a literal tag makes each member exact; guards are trusted; callbacks keep unchanged variables.
Type-level tools
- 4Generics and constraintsA generic carries the caller's type from input to output; a constraint says what it must have; keyof and T[K] tie keys to values.
- 5Utility, mapped and conditional typesA mapped type loops over keys; a conditional type tests, per union member; infer reads a part; utility types are built from both.