Skip to content

TypeScript Practice

Master the type system, generics, mapped types, and runtime safety patterns.

ConceptDetails
Memory ModelV8 GC, prototypal inheritance, closures, WeakRef/FinalizationRegistry
Type SystemStructural, gradual, mapped types, conditional types, template literals
Error Handlingtry/catch (untyped), Result<T,E> pattern, never for exhaustiveness
ConcurrencyEvent loop, Promise, async/await, Web Workers, SharedArrayBuffer
Buildtsc, tsx, esbuild, vitest for testing
StandardTypeScript 5.x, ES2023+ target
  • Discriminated unions with kind field for exhaustive switching
  • satisfies operator for type checking without widening
  • Branded types for nominal typing (type USD = number & { __brand: 'USD' })
  • as const for literal type inference
  • Mapped types (Partial, Required, Pick, custom)
  • Conditional types with infer for type-level computation
  • Template literal types for string pattern enforcement
  • using keyword (TC39 explicit resource management)
Terminal window
practice/bin/ol list build typescript # which of these have references yet
practice/bin/ol start build typescript 01 # clone it stubbed into .scratchpad/
practice/bin/ol check build typescript 01 # run it; exit code is the verdict
practice/bin/ol diff build typescript 01 # your attempt against the reference

Exercises 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.

#ExerciseConceptsDifficulty
01Type-safe event emitterGenerics, mapped types, Parameters<T>⭐⭐⭐
02Result/Option monadsDiscriminated unions, method chaining, never⭐⭐
03Schema validator (like Zod)Template literals, recursive types, infer⭐⭐⭐⭐⭐
04Reactive signals (like Solid)Proxies, dependency tracking, batched updates⭐⭐⭐⭐
05Type-safe SQL query builderTemplate literal types, conditional types⭐⭐⭐⭐
06Middleware pipeline (like Koa)Generics, async composition, context threading⭐⭐⭐
07State machine (typed transitions)Mapped types, phantom states, never transitions⭐⭐⭐⭐
08DI container (type-safe)Symbol keys, Map, WeakMap, interface registry⭐⭐⭐
09Incremental type checker (subset)AST, inference, unification, variance⭐⭐⭐⭐⭐
10Streaming JSON parserAsyncGenerator, backpressure, ReadableStream⭐⭐⭐⭐