~/alexsh.blog

$ cd writing/advanced-typescript && cat README

Advanced TypeScript

This guide covers 20 advanced TypeScript type-system features, ordered by prerequisite dependencies. Each topic builds on concepts from previous ones, creating an optimal learning path from foundational patterns to expert-level type gymnastics.

→ start at 01-discriminated-unions-and-exhaustiveness20 parts · ~20 min · February 9, 2026

$ ls -l

  1. 01Discriminated Unions and ExhaustivenessDiscriminated unions (tagged unions) use a common property to distinguish between variants, enabling TypeScript to narrow types in control flow.1 min
  2. 02satisfies Operator and const AssertionsThe satisfies operator (TS 4.9+) and as const assertions are essential modern TypeScript tools.1 min
  3. 03Advanced Infer Patterns and PositionsThe infer keyword is TypeScript's most powerful type extraction tool, but its behavior changes dramatically based on position (covariant vs contravariant).1 min
  4. 04Distributive Conditional TypesDistributive conditional types automatically distribute over union types when the checked type is a naked type parameter.1 min
  5. 05Tuple ManipulationTuple manipulation involves transforming fixed-length array types with heterogeneous element types.1 min
  6. 06Template Literal TypesTemplate literal types bring string manipulation to the type level, allowing you to create new string literal types through concatenation and pattern matching.1 min
  7. 07Mapped Type Key RemappingKey remapping in mapped types (TS 4.1+) allows you to transform the keys of an object type during mapping using the 'as' clause.1 min
  8. 08Recursive Conditional TypesRecursive conditional types allow you to define types that reference themselves, enabling complex type transformations that operate on nested structures of arbitrary depth.1 min
  9. 09Variance and ContravarianceVariance describes how subtyping relationships between complex types relate to subtyping between their components.1 min
  10. 10Union to Intersection ConversionConverting a union type to an intersection type exploits function parameter contravariance to "flip" a union into an intersection.1 min
  11. 11Declaration MergingDeclaration merging combines multiple declarations with the same name into a single definition.1 min
  12. 12Advanced Module and Namespace PatternsAdvanced module patterns include ambient modules, wildcard declarations, path mapping, and sophisticated declaration file authoring.1 min
  13. 13Branded Types (Nominal Typing)Branded types create nominally distinct types that are structurally identical but not assignable to each other.1 min
  14. 14Type-Safe Builder PatternThe type-safe builder pattern uses TypeScript's type system to enforce that all required fields are set before building, prevent setting the same field twice, and provide accurate autocompletion at each step.1 min
  15. 15Deep Path Types and Dot Notation AccessDeep path types allow you to express paths into nested objects using dot notation strings (like "user.address.city") and retrieve the types at those paths.1 min
  16. 16Type-Safe State MachinesType-safe state machines use TypeScript's type system to enforce valid state transitions at compile time.1 min
  17. 17Type-Level ArithmeticType-level arithmetic involves performing mathematical operations like addition, subtraction, and comparison entirely within TypeScript's type system using tuple lengths.1 min
  18. 18Currying and Function Composition TypesTyping curried functions and function composition at the type level requires sophisticated manipulation of function signatures and parameter tuples.1 min
  19. 19Higher-Kinded Type (HKT) SimulationHigher-kinded types are type constructors (like Array without a type argument).1 min
  20. 20Type-Level JSON ParsingType-level JSON parsing is the ultimate test of TypeScript's type system.1 min