When I do this:
const Button = styled.button.attrs((props:ButtonProps) => ({
primary: props.buttonType === 'primary',
secondary: props.buttonType === 'secondary',
critical: props.buttonType === 'critical',
small: props.buttonSize === 'small',
}))
I get the following error with TS:
My Types are as follows
type ButtonProps = {
buttonType?: 'primary' | 'secondary' | 'critical';
children?: React.ReactChild | React.ReactChild[];
buttonSize?: 'small' | 'medium';
};
The problem fixes itself however when I pass down the original props with the edited attributes like thus:
const Button = styled.button.attrs((props:ButtonProps) => ({
primary: props.buttonType === 'primary',
secondary: props.buttonType === 'secondary',
critical: props.buttonType === 'critical',
small: props.buttonSize === 'small',
...props
}))
I've seen elsewhere online I'm supposed to type props in attrs
the same way I'd do so with plain styled-components like here:
const Button = styled.button.attrs<ButtonProps>((props) => ({
primary: props.buttonType === 'primary',
secondary: props.buttonType === 'secondary',
critical: props.buttonType === 'critical',
small: props.buttonSize === 'small',
}))
But this just gives me the same error as in the image :/