Skip to content

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

  1. 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.
  2. 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.
  3. 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

  1. 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.
  2. 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.

Types at the boundary

  1. 6Types vanish at runtime, validate at the boundaryThe types stay behind in the build; at every boundary a runtime schema checks what really arrived, and the type is read off that schema.