I am working on a button component that has variant
prop to determine it's color. Here is simplified version
interface Props extends React.HTMLProps<HTMLButtonElement> {
variant: 'yellow' | 'green';
}
function Button({ variant, ...props }: Props) {
console.log(variant);
return (
<button
type="button"
{...props}
/>
);
}
I am getting typescript error under my type
that says:
(JSX attribute) ButtonHTMLAttributes.type?: "button" | "submit" | "reset" | undefined Type 'string' is not assignable to type '"button" | "submit" | "reset" | undefined'.ts(2322) index.d.ts(1872, 9): The expected type comes from property 'type' which is declared here on type 'DetailedHTMLProps, HTMLButtonElement>'
So I am not sure if I am extending to button props correctly? Perhaps there is another way?