Typescript error when sharing styles across components that have variant attributes
Bug report
Describe the bug
I am creating a variable called sharedTypo using the css function, to share styles across components.
It has variant called variant with a value of h1.
I am following this part of the documentation: https://stitches.dev/docs/typescript#type-a-css-object
const sharedTypo = css({
variants: {
variant: {
h1: {
fontSize: "30px"
}
}
}
});
When I apply my sharedTypo to a styled component, like const Text = styled("p", sharedTypo, {..., my styled component has a Typescript error saying that it does not recognize the variants variant: h1 coming from my sharedTypo.
const Text = styled("p", sharedTypo, {
variants: {
color: {
red: {
color: "red"
}
}
},
compoundVariants: [
{
// TYPESCRIPT ERROR HERE SAYING VARIANT DOES NOT EXIST
variant: "h1",
color: "red",
css: {
padding: "20px"
}
}
]
});
The css is computed as expected though (it recognized the variant), which suggest that it is indeed a Typescript error versus Stitches not supporting this feature. Note: this worked with version 1.0.0, but stopped starting 1.0.1
To Reproduce
https://codesandbox.io/s/zen-boyd-v0myz?file=/src/App.tsx
Expected behavior
I expected Typescript to not display any errors.
Screenshots
System information
- Version of Stitches: > 1.0.0
- Version of Node.js: [e.g. 10.10.0]
Additional context
Add any other context about the problem here.
Experienced the same thing trying to use shared variants but changing the defaultVariants value for another component
We reached a TS limitation to compose variants from other components. It's quite complex. We'll need to try again, or eventually wait for TS to get better - currently there are lots of limitations we need to work around.
However, we should be able to at least prevent the error.
Related: https://github.com/modulz/stitches/issues/848
@peduarte, might this error prevention make it in the next release?
@MichaelDM we'll look into this 🙏
Any updates on this? This is something that would really help our team.