destack.sh
docstemplatesblog
Language
  1. Setup
  2. TypeScript
  3. Soundness
  4. Primitives
  5. Expressions
  6. Control Flow
  7. Decorators
  8. Static Ifs
  9. Type Aliases
  10. Objects
  11. Arrays
  12. Tuples
  13. Functions
  14. Captures
  15. Generators
  16. Async and Promise
  17. Classes
  18. Enums
  19. Unions
  20. Narrowing
  21. Interfaces
  22. Generics
  23. Type Operators
  24. TSX
  25. Modules
  26. Globals
  27. TypeScript++
  28. Runtime
  29. Standard Library
  30. Configuration
  31. Static Analysis
  32. Dynamic Analysis
  33. Deployment
menu
Language
  1. Setup
  2. TypeScript
  3. Soundness
  4. Primitives
  5. Expressions
  6. Control Flow
  7. Decorators
  8. Static Ifs
  9. Type Aliases
  10. Objects
  11. Arrays
  12. Tuples
  13. Functions
  14. Captures
  15. Generators
  16. Async and Promise
  17. Classes
  18. Enums
  19. Unions
  20. Narrowing
  21. Interfaces
  22. Generics
  23. Type Operators
  24. TSX
  25. Modules
  26. Globals
  27. TypeScript++
  28. Runtime
  29. Standard Library
  30. Configuration
  31. Static Analysis
  32. Dynamic Analysis
  33. Deployment
Docs/Language/TypeScript
98 tokens
mdtxt

Unions

Nominal and structural discriminated unions.

Unions

  • sum types
  • regular unions
  • nominal and structural discriminated unions
  • discriminated tags lower as simple types
src/events.ds.ds
1type Event =2    | { kind: "ready"; port: uint16 }3    | { kind: "closed"; reason: string };
  • union member dispatch resolves every variant
  • one common implementation stays static
  • otherwise the compiler emits a runtime case dispatch and unions the result types
← EnumsNarrowing →
discordxgithub
2026.8.3alpha