Well-typed props document component APIs and catch misuse at compile time. This lesson covers optional props, children typing, extending HTML attributes, and advanced prop patterns.
Prop Type Patterns
Define an interface for each component's props. Mark optional fields with ?. Use union types for variant props: variant: 'primary' | 'secondary'.
Extend native element props: ButtonProps extends React.ComponentProps<'button'> spreads standard button attributes.
Components that render as different elements (as="a" vs button) need generic typing — libraries like Radix use complex generics; start simple with union as: 'button' | 'a'.
Safe Prop Spreading
Omit custom props before spreading rest to DOM to avoid React unknown prop warnings.