You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Variants which contain numeric strings (e.g. "-12") and number keys (e.g. 12) are assigned a 'number' type when generating a union using the VariantProps type
#1132
Open
willdspd opened this issue
Dec 30, 2022
· 0 comments
I would expect, if I then passed StyledBox to Stitches.VariantProps (e.g. Stitches.VariantProps<typeof StyledBox>), the following type would be generated considering that the keys are both technically numeric:
However, the following type is generated, which contains the 'number' type:
margin?: number | "-12" | "12" | ({
"@md"?: number | "-12" | "12" | undefined;
"@lg"?: number | "-12" | "12" | undefined;
"@initial"?: number | "-12" | "12" | undefined;
} & {
[x: string]: number | "-12" | "12" | undefined;
}) | undefined
Naturally this is not ideal for strong typing as any number can be accepted as a variant key. However, interestingly, if I change the variant negative key (e.g. "-12") to a non numeric string (e.g. "neg12") the types are correct/how I would want them in my first example. For example:
This is not a big issue as I can just change any numeric strings (e.g. "-12") to non-numeric strings (e.g. "neg12") in my variant keys, but I hope it's something that can be fixed in the future.
Stitches version: 1.2.8
The text was updated successfully, but these errors were encountered:
Let's say I create a component with a variant called 'margin', which has a mix of numeric and numeric string keys, like so:
I would expect, if I then passed
StyledBox
to Stitches.VariantProps (e.g.Stitches.VariantProps<typeof StyledBox>
), the following type would be generated considering that the keys are both technically numeric:However, the following type is generated, which contains the 'number' type:
Naturally this is not ideal for strong typing as any number can be accepted as a variant key. However, interestingly, if I change the variant negative key (e.g. "-12") to a non numeric string (e.g. "neg12") the types are correct/how I would want them in my first example. For example:
And the correctly generated types:
This is not a big issue as I can just change any numeric strings (e.g. "-12") to non-numeric strings (e.g. "neg12") in my variant keys, but I hope it's something that can be fixed in the future.
Stitches version: 1.2.8
The text was updated successfully, but these errors were encountered: