so I get the famous "No overload matches this call" error when using Typescript + Styled-Components + Styled-System.
The solutions I found so far require me to pass a generic type/interface
to the styled component. Which I do with the ButtonProps
. So what am I doing wrong?
Here is my code:
styled-system type imports
import {
background,
BackgroundProps,
border,
BorderProps,
color,
ColorProps,
layout,
LayoutProps,
shadow,
ShadowProps,
typography,
TypographyProps,
variant
} from "styled-system"
Type declaration
interface VariantProps {
variant: "submit" | "cancel"
}
type ButtonProps = BackgroundProps &
BorderProps &
ColorProps &
LayoutProps &
ShadowProps &
TypographyProps &
VariantProps
Styled component definition
const Button = styled.button<ButtonProps>`
${background}
${border}
${color}
${layout}
${shadow}
${typography}
${({
disabled,
theme
}) => variant({
variants: {
submit: {
background: theme.gradients.blue,
border: "none",
borderRadius: "sm",
boxShadow: "0px 10px 5px -5px rgba(93,159,255, 0.3);",
color: theme.colors.white,
cursor: disabled ? "not-allowed" : "default",
fontSize: "sm",
fontWeight: 600,
my: "16px",
minHeight: "50px",
opacity: disabled ? 0.5 : 1,
}
}
})}
`;
Usage of the styled component and where the error occurs (<Button {...props}>
)
const AnimatedButton: React.FC<ButtonProps> = ({
children,
...props
}) => {
return (
<Button {...props}>
{children}
</Button>
)
}