12 · TypeScript
Phase: 4 · Estimate: 3–4 weeks · Prerequisites: 04 JavaScript
Why it matters
TypeScript is the de facto standard for professional front-end work. The basics (type annotations) are easy. The real value is in designing types so invalid states can't be represented, and so a library's API feels "magical" to its users.
Concept map
Basics
- Primitive types, unions, intersections, literal types
- Interfaces vs type aliases
- Basic generics
-
tsconfig:strict,target,module,moduleResolution
Intermediate
- Narrowing:
typeof,in, discriminated unions, type predicates,asserts - Utility types:
Partial,Pick,Omit,Record,ReturnType,Awaited -
unknownvsanyvsnever -
satisfies,as const, const type parameters - Typing React components (generic props, polymorphic
as)
Deep dive
- Conditional types,
infer, distributive conditional types - Mapped types and key remapping
- Template literal types
- Variance, structural typing, and soundness holes
- Type checker performance, project references,
isolatedDeclarations
How to learn
- Finish the TypeScript Handbook.
- Work through type-challenges from easy → medium → hard.
- Rewrite one module with
strict+noUncheckedIndexedAccessand note the bugs you find. - Read the
.d.tsfiles of a library whose API you like (Zod, TanStack Query).
Check your understanding
- Why can
string[]be assigned toreadonly string[]but not the other way around? - What is a distributive conditional type, and when do you need
[T] extends [U]? - How do discriminated unions remove the need for
undefinedchecks? - Why is TypeScript unsound, and where are the holes?
Practice projects
| Level | Project | What it trains |
|---|---|---|
| Basic | Migrate a JS project to strict TS | Basics |
| Intermediate | A typed API client generated from an OpenAPI schema | Generics, inference |
| Deep | A mini Zod-style validator with type inference (z.infer) | Conditional & mapped types |
Primary sources
Related toolkit
- Every package in this repo is written in strict TS. See
tsconfig.base.json