-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect TS type/inference for compose function in CVA beta #256
Comments
Thanks for this @kaelansmith! Honestly I need to do a bit more thinking/digging here as I'm not even sure if |
@joe-bell for sure -- I did some of my own testing and was pleasantly surprised to find it worked how I hoped it would; here's an example: const A = cva({
base: 'base-A',
variants: {
style: {
primary: 'primary-A',
},
},
});
const B = cva({
base: 'base-B',
variants: {
style: {
primary: 'primary-B',
secondary: 'secondary-B',
},
newBStyle: {
fancy: 'fancy-B',
},
},
});
const C = cva({
base: 'base-C',
variants: {
style: {
tertiary: 'tertiary-C',
},
newBStyle: {
fancy: 'fancy-C',
},
},
});
const merged = compose(A, B, C);
const result = merged({ style: 'primary', newBStyle: 'fancy' });
// result => "base-A primary-A base-B primary-B fancy-B base-C fancy-C" This result is exactly what I'd expect; I like that One interesting behavior I came across in my testing, which I'm not sure about, is how // same example code as before, but added defaultVariants to `B`:
const A = cva({
base: 'base-A',
variants: {
style: {
primary: 'primary-A',
},
},
});
const B = cva({
base: 'base-B',
variants: {
style: {
primary: 'primary-B',
secondary: 'secondary-B',
},
newBStyle: {
fancy: 'fancy-B',
},
},
defaultVariants: { // added
newBStyle: 'fancy',
},
});
const C = cva({
base: 'base-C',
variants: {
style: {
tertiary: 'tertiary-C',
},
newBStyle: {
fancy: 'fancy-C',
},
},
});
const merged = compose(A, B, C);
const result = merged({ style: 'primary' }); // removed `newBStyle: 'fancy'` because it's set as default in B
// result => "base-A primary-A base-B primary-B fancy-B base-C" This result excludes |
Would the possibility to specify a |
You can always pass the whole result in to |
Describe the bug
First off, thank you very much for your work on cva. I'm using
compose
from the beta version of cva@1.0.0-beta.1
to merge two cva components; functionally it works as expected, but the resulting Type appears to be incorrect, thereby breaking VSCode autocomplete for the composed/merged cva component. I wrote my ownCompose
type that appears to fix it (see further below).To reproduce
I'm really not a TS expert, but with the help of good ol' ChatGPT I came up with this alternative Typing for
compose
that seems to fix the issue:Happy to get a PR going with these changes, but wanted to get your take on this and/or figure out if I'm missing something.
The text was updated successfully, but these errors were encountered: