Repository navigation
How can I get the type of intent? #67
|
Hi! I am trying to pass an intent, but I am getting TypeScript errors.
How would I be able to get the type of intent without having to manually type out the string literal? I want to be able to pass in an intent prop and if I update the Button component the intent type will update as well. Currently I am manually updating a type Thanks! |
Replies: 1 comment
|
https://github.com/joe-bell/cva#variantprops You can use // components/button.ts
import type { VariantProps } from "class-variance-authority";
import { cva } from "class-variance-authority";
/**
* Button
*/
export type ButtonProps = VariantProps<typeof button>;
export type ButtonIntent = ButtonProps['intent']
export const button = cva(/* … */); |
https://github.com/joe-bell/cva#variantprops
You can use
VariantPropsto extract the type, and then pick off the type like a standard object (YourType[‘intent’])