TypeScript
CVA is written in TypeScript and ships full type declarations. TheVariantProps utility type is the primary tool for connecting your cva definitions to your component interfaces.
Extracting variant types with VariantProps
VariantProps<typeof component> infers the variant prop types directly from your cva definition. This means your types and your variant config stay in sync automatically — no manual duplication:
components/button.ts
Using VariantProps in a component
- React
- Other frameworks
Extend your component’s props interface with
VariantProps and forward the variant props into the cva call:components/Button.tsx
Required variants
All variant props are optional by default (they can fall back todefaultVariants). To make a variant required, use TypeScript utility types:
components/button.ts
The class and className props
CVA accepts either class or className for one-off class overrides. The two props are mutually exclusive — the type system prevents you from passing both at once:
VariantProps intentionally omits both class and className from the extracted type. Pass them directly to the component call instead:
The ClassValue type
ClassValue is re-exported from CVA and mirrors the type accepted by clsx. Use it when you want a component to accept arbitrary class inputs:
ClassValue for an extra classes prop and merge it with the CVA output:
components/button.ts
