~/talk

Scale Your Components With Tagged Unions and Factory Pattern

Talkat ReactNext 2025 · on Monday, 2025-12-15· [react, typescript]
links:none on file
slides:none on file

Shows a concrete migration: a chat-bubble component with many optional props is refactored into TypeScript tagged unions plus extracted per-variant components and a factory components switch, moving impossible runtime states into compile-time errors. Uses TypeScript narrowing, literal discriminants and TypeScript 4.9’s satisfies with never check to force exhaustiveness. The built demo compiles and rejects invalid prop combinations, reduces JSX conditionals, and warns when a new variant is added; works well for distinct-UI same-concept variants but not for tiny boolean toggles or divergent business logic.

AI-written summary · about

  1. 0:00Introduction
  2. 1:07Monolithic component problems
  3. 3:34Tagged unions for type safety
  4. 5:18Demo: Discriminated unions in TypeScript
  5. 6:23Type narrowing with tagged unions
  6. 8:52Factory pattern for composition
  7. 10:37Benefits of isolated variants
  8. 12:47Compile-time checks with satisfies
  9. 13:30When to use or avoid
  10. 14:13Final advice
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.