TypeScript Practice
Master the type system, generics, mapped types, and runtime safety patterns.
Language Essentials
Section titled “Language Essentials”| Concept | Details |
|---|---|
| Memory Model | V8 GC, prototypal inheritance, closures, WeakRef/FinalizationRegistry |
| Type System | Structural, gradual, mapped types, conditional types, template literals |
| Error Handling | try/catch (untyped), Result<T,E> pattern, never for exhaustiveness |
| Concurrency | Event loop, Promise, async/await, Web Workers, SharedArrayBuffer |
| Build | tsc, tsx, esbuild, vitest for testing |
| Standard | TypeScript 5.x, ES2023+ target |
Key Idioms
Section titled “Key Idioms”- Discriminated unions with
kindfield for exhaustive switching satisfiesoperator for type checking without widening- Branded types for nominal typing (
type USD = number & { __brand: 'USD' }) as constfor literal type inference- Mapped types (
Partial,Required,Pick, custom) - Conditional types with
inferfor type-level computation - Template literal types for string pattern enforcement
usingkeyword (TC39 explicit resource management)
Reference Documentation
Section titled “Reference Documentation”- TypeScript Handbook — free, official
- TypeScript Playground — experiment online
- type-challenges — free, type gymnastics
- Programming TypeScript (Cherny) — comprehensive
- Effective TypeScript (Vanderkam, 2nd ed.) — 83 practical items
Practising these
Section titled “Practising these”practice/bin/ol list build typescript # which of these have references yetpractice/bin/ol start build typescript 01 # clone it stubbed into .scratchpad/practice/bin/ol check build typescript 01 # run it; exit code is the verdictpractice/bin/ol diff build typescript 01 # your attempt against the referenceExercises are ordered by concept, not by difficulty, so pick by the stars rather than by the number. An exercise listed below with no reference yet is a row in this table and nothing more; see the practice path for how the harness works.
Exercises
Section titled “Exercises”| # | Exercise | Concepts | Difficulty |
|---|---|---|---|
| 01 | Type-safe event emitter | Generics, mapped types, Parameters<T> | ⭐⭐⭐ |
| 02 | Result/Option monads | Discriminated unions, method chaining, never | ⭐⭐ |
| 03 | Schema validator (like Zod) | Template literals, recursive types, infer | ⭐⭐⭐⭐⭐ |
| 04 | Reactive signals (like Solid) | Proxies, dependency tracking, batched updates | ⭐⭐⭐⭐ |
| 05 | Type-safe SQL query builder | Template literal types, conditional types | ⭐⭐⭐⭐ |
| 06 | Middleware pipeline (like Koa) | Generics, async composition, context threading | ⭐⭐⭐ |
| 07 | State machine (typed transitions) | Mapped types, phantom states, never transitions | ⭐⭐⭐⭐ |
| 08 | DI container (type-safe) | Symbol keys, Map, WeakMap, interface registry | ⭐⭐⭐ |
| 09 | Incremental type checker (subset) | AST, inference, unification, variance | ⭐⭐⭐⭐⭐ |
| 10 | Streaming JSON parser | AsyncGenerator, backpressure, ReadableStream | ⭐⭐⭐⭐ |