React conditional props with Typescript
summary
Shows a concrete pattern that uses TypeScript discriminated unions to make a CTA component accept exactly one valid prop set: discriminated unions make href required for the link variant and impossible for button or no-op, and IDE autocomplete plus compile-time errors enforce that. Implementation uses React.ComponentPropsWithoutRef to inherit HTML props, demoed in CodeSandbox, and it works; known tradeoffs: kind must be preserved (or null) and props must be destructured later.
AI-written summary · about
chapters (13)
- 0:00Introduction and speaker intro
- 0:21Talk agenda overview
- 1:04Defining the problem with examples
- 3:29Solution requirements and goals
- 4:32Solution approach and setup
- 6:39Implementing discriminated unions
- 8:25Live code demonstration
- 9:27Additional benefits of the solution
- 10:10How type narrowing works
- 10:30Current solution limitations
- 10:51Related concepts and patterns
- 12:59Advanced TypeScript techniques
- 13:20Conclusion and further research
