6 lessons · ~68 min · typescript 5.7
ts types in anger
six lessons on the parts of typescript's type system that actually
earn their keep on a production codebase. each lesson is a single
pattern, applied to a real boundary — api responses, ids, route
tables, currency, request schemas. interactive: every lesson has a
type-challenge quiz and a side-by-side variant explorer so you can
see what the compiler actually infers, not just what we claim.
what you'll come out with
-
a reflex for reaching for discriminated unions whenever you'd
otherwise reach for a boolean flag.
-
branded ids so a
UserId can't be passed where an
OrderId is expected — at compile time, with zero
runtime cost.
-
template literal types for route patterns, event names, and any
string the compiler should be able to verify.
-
conditional types with
infer, and the discipline to
know when to stop reaching for them.
-
mapped types and key remapping — the workhorse behind
Partial, Pick, and most of the utility
types you use without thinking.
-
type predicates and assertion functions, applied where they
belong (system boundaries) and not where they're a smell
(internal code that should already have proven types).
how the lessons work
-
each lesson is one pattern in one bite (10–14 min). read it,
do the type-challenge, click through the variants.
-
code samples are typescript 5.7. snippets compile against the
published version, not a future preview.
-
opinionated. when there are two ways to do something and one is
structurally better, the lesson says so — and says why.
lessons
- 01 discriminated unions model state the compiler can verify. exhaustive switches, assertNever, and api response shapes that can't lie. 10m
- 02 branded types make primitives unforgeable at compile time, with zero runtime cost. UserId is not OrderId — and TS will believe you. 10m
- 03 template literal types strings the compiler understands. route patterns, event names, css-in-ts, and parsing — all without a single regex. 12m
- 04 conditional types & infer type-level branching. Awaited and ReturnType from scratch. when to reach for it and when not to. 14m
- 05 mapped types & key remapping Partial, Pick, Required — built from primitives. key remapping with `as`. the workhorse of the type system. 12m
- 06 type predicates at the boundary user-defined guards and assertion functions. where they fit (the boundary). where they're a smell (everywhere else). 10m