Skip to content
Preptima
mediumConceptCodingMidSeniorStaff

How do you use TypeScript to make a component's props hard to misuse?

A safe TypeScript component props API models legal states with discriminated unions, ties related props together with generics and keeps any out of the public surface.

4 min readUpdated 2026-08-15

Answer

Short answer

Make misuse impossible by typing only the legal prop combinations. Use discriminated unions for mutually exclusive states, generics when one prop depends on another, and never checks so a new variant cannot be added silently.

Was this answer helpful?

Likely follow-ups

  • Your union has eight variants and the render function is a wall of branches. When is that a typing problem and when is it a component-boundary problem?
  • How would you type a polymorphic component that renders as whatever element the caller passes in the as prop?
  • What does the satisfies operator give you that a type annotation on the same object does not?
  • A colleague types a callback prop as (e: any) => void to silence an error. What breaks downstream that they will not see?

Related questions

Further reading