VariantProps
A TypeScript helper from CVA that extracts a component's prop types from its cva() definition.
In more detail
type ButtonProps = VariantProps<typeof button> gives intent?: "primary" | "danger" and size?: "sm" | "lg" automatically. Adding a variant then updates the props with no second list to keep in sync.
Related terms
- Class Variance Authority — A small JavaScript library that turns a component's variants, such as intent and size, into the right list of CSS classes.
- TypeScript — JavaScript with added type annotations, checked by a compiler before the code runs.
- union type — A type that allows one of several listed types or values, written with a vertical bar, such as int | None in Python or "small" | "large" in TypeScript.
Taught in
- Class Variance Authority: Type-Safe Variant & Prop Orchestration — Design Systems & Component Engineering