-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
fix createUseStyles
types
#1352
Conversation
I don't think this test failure is related to my changes..
|
That's because we are not able to run browserstack tests for external contributors |
Is this a breaking change for the user? |
Don't think so. Types should never trigger breaking changes. That's said, I notice some new errors on my code if I wrote a function that return If that not a fix and JSS support also Other then that, it should accept basically anything, including custom css properties like: const useStyles = createUseStyles({
root: {
fontSize: 12,
customFont: 'foo' // <- non-existing property
}
}); |
|
If someone suddenly can't compile types after updating a minor change, how is this not breaking users code? |
I think that if the user did something wrong and the type check suddenly catch that on a version update it's a good thing. It's better to failed on compile time then on runtime. As far as I know, those types are align with the current implementation. The only contradiction that I found is on the It's seems that JSS works with |
Falsy values are supported for the rule function (function returning an object with properties/values) But https://github.com/cssinjs/jss/blob/master/packages/jss/src/plugins/styleRule.js#L45 method styleRule.prop can set and get in one method and so if the second argument is undefined, it will act as a getter, so it turns out we have an inconsistency with function values https://github.com/cssinjs/jss/blob/master/packages/jss-plugin-rule-value-function/src/index.js#L75 because if To make it consistent we need to support falsy values here |
2 questions:
|
The thing is any change is potentially a breaking change. Semver is here to communicate to the user: "you will have to change your code and verify it works". |
I don't want to change functionality in this PR. If export type JssStyle = {
[K in keyof NormalCssProperties | string]:
| NormalCssValues<K>
| JssStyle
| ((data: any) => NormalCssValues<K> | JssStyle | undefined)
} To answer your questions:
|
In this case right now we support falsy values for function rules and only a null for function values. |
What's the different between "function rules" and "function values"? It's not clear to me.. |
Regarding breaking changes in types: https://twitter.com/FezVrasta/status/1270648268012339203?s=20 argument resonates with me In theory, it should have been breaking change, but both ts and flow are a mess in terms of breaking changes so we shouldn't care either breaking users types in minor versions. |
I think now we align with the docs. |
I think we should align with how it is supposed to be used: both null and undefined returned from both function rule and function value should result in removing that rule or value |
OK, Done. |
Alright, lets try releasing it as a minor change and see what happens. Can you please write a summary in the description of this PR and very short one in the changelog after |
Done |
Here is TS's opinion on breaking changes DefinitelyTyped/DefinitelyTyped#25677 (comment) |
released in v10.3.0 |
Just tested on large project, all types working fine. |
I just upgraded a typescript project from |
@afzalsayed96 sorry to hear that, you will have to report separate issues, also check out the changelog between the versions |
Any plans to support falsy values in function values? I'm widely using something like below pattern everywhere in my codebase: block: ({ height, width }: { height?: number, width?: number }) => ({
height,
width
}) |
@afzalsayed96 can you attach the typescript errors you get (preferably on a new issue, linked to this one + tag me)? |
Corresponding issue (if exists):
#1351
What would you like to add/fix?
This PR re-add TypeScript support for
createUseStyles
by redefiningJssStyle
recursively. This change enables IDEs to autocomplete known CSS properties and also allow unknown properties as well. In addition, it fixes the return type for function value and function rules, making both acceptnull
,false
orundefined
values to disable the rule/class.Todo
packages/jss/tests/types/Styles.ts