~/talk

TypeScript Patterns for Better React Components

Talkat CityJS Berlin 2024 · 2024-01-05..02-02· [typescript, react]
slides:none on file

Explains concrete TypeScript solutions for React: use discriminated unions or string literal unions instead of Boolean props, prefer string literals over enums to avoid runtime bloat, and prefer ComponentProps/JSXIntrinsic for accurate HTML attributes. Shows polymorphic components typed with React.createElement, Compound components via React.cloneElement, and a forwardRef augmentation using higher‑order type inference. Covers createContext nullable unions, overloads for variant props, prefers interfaces for editor speed, recommends return annotations, and runtime validation with Zod.

AI-written summary · about

  1. 0:00Introduction to TypeScript in React
  2. 1:25Boolean Props vs Variants
  3. 3:48Enhancing Components with HTML Types
  4. 5:55Compound vs Polymorphic Components
  5. 7:20Typing React Forward Refs
  6. 8:25Context with and without Values
  7. 9:50Overload Function Components
  8. 11:15Type vs Interface Performance
  9. 12:43Deprecating Props and Types
  10. 14:30Handling TypeScript Errors
  11. 14:50Why TypeScript Matters
~/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.