Skip to main content

TypeScript

CVA is written in TypeScript and ships full type declarations. The VariantProps 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

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 to defaultVariants). 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:
This means 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:
A common pattern is to accept ClassValue for an extra classes prop and merge it with the CVA output:
components/button.ts