Conversation
|
Just saw the CI fail due to some peculiar browser issue. But I didn't touch any JavaScript. 🤔 Is this something to be worried about? |
|
From Ryan's Comment on microsoft/TypeScript#39008, it unfortunately seems like Such a change would also remove one of the caveats I mentioned while getting things more ready for what microsoft/TypeScript#26349 would hopefully bring to the table soon. Thoughts? I could apply the change if desired. |
moshest
left a comment
There was a problem hiding this comment.
Overall I liked that a lot. Great job!
|
I'm a little preoccupied right now. But just in case, really quickly, I wanted to call attention to:
Some thoughts on those would be helpful before merging (if everything gets approved). |
b187f47 to
44c1afd
Compare
|
Rebased onto master. |
k-yle
left a comment
There was a problem hiding this comment.
This is great (: I've left a few comments
|
Just for the record, I intend to clean up the commit history with a local |
9d0eb91 to
fac9793
Compare
|
Since everything got approved sooner than I expected, I reduced my commits today (instead of waiting until tomorrow). These are not breaking changes for JS. However, they are breaking changes as far as TS is concerned due to the new type definitions (particularly for The PR is approved and the history is reduced to a single commit. @kof, if these changes are acceptable, then this PR is ready to merge. Otherwise, if there are any changes you or anyone else would like me to add, I'd be happy to include them. |
|
Is it acceptable to release this under minor version increase? |
@kof, The short answer is that I'm not sure. But in my opinion, a minor version increase is probably fine. I mainly feel this way since the JS API hasn't changed, and this is an improvement on the TS types, where features were previously missing.
I tried to do some research on this but didn't find any "objectively right" answers. I saw #1255, where some users were upset about breaking type changes. So...some people would likely get upset with a minor increase. But I also saw your link to Ryan's comment on breaking type changes at the end of that issue. Ryan has additional comments that may be related to the matter here and here. Additionally, other libraries like CRA seem to release minor versions with breaking changes if the changes aren't expected to be too significant for most users. I also noticed your comments on #1351. If the types truly haven't stabilized yet, then it may be practical to forego bumping the major version since complaints/issues related to types would be found often. Technically speaking, if the types were back on DT, users would encounter breaking changes without bumping major versions anyway. (Btw, I think the types are better housed here than on DT.) If there aren't any large incoming JS changes, then bumping the major version only for this TS change (especially if the definitions haven't fully stabilized yet) feels a bit weird. I'm sure there'll be people who disagree. But after observing a few discussions -- and just thinking about it practically -- I find an overly religious following of semver unhelpful. (I do like semver though. And generally speaking, it's practical and desirable.) Personally, I support going with a minor release. If this does happen to be released as a minor change, I'll take the heat of the complaints. The decision is up to you though. (Others are free to chime in.) Warnings about breaking changes in a changelog, joined with a useful migration guide, would probably facilitate a minor release. It would hopefully reduce complaints too. |
|
If anyone's interested in an opinion besides my own on the versioning, I saw this comment from a moderator in the Testing Library Discord.
I couldn't find this person's GitHub, so I don't know who they were. But it's another thought! If strictly, religiously following semver is the goal of this project, then a major version would likely make more sense. But again, given the volatility of the types, that may cause unnecessarily frequent major bumps (unless the types stabilize some day). |
|
No rush on the PR, but I'm curious to know what the intentions with this PR will be? My team would benefit from being able to employ the new type changes (as would others). And I don't feel comfortable starting on the work for the lazy migration HOC docs (TypeScript) until I know this is finalized. I'm just trying to get an idea of the timeline. |
|
@ITenthusiasm I am finishing #1456 and then gonna merge this one and make a release with all recent changes as a minor |
This commit applies changes to ensure the `createUseStyles` hook has accurate TS intellisense for props and themes. The details of the work may be found below. Note: Changes are for TypeScript files **only**. Minimal changes were applied in order to minimize regression testing and the potential for cascading negative effects. General: * Updated .eslintignore to ignore TSX type tests in addition to TS type tests. JSS: * `Style` now expects type parameters for `Props` and `Theme`. * `JssStyle` now expects type parameters for `Props` and `Theme`. * `Func` now expects type parameters for `Props` and `Theme`. * Types are arranged to prevent unnecessary/confusing parameter shadowing. Once a function in a style object is introduced, if the function returns an object, none of the returned object's properties (or nested properties) may define a function that has access to `Props` or `Theme`. * Updated tests for `Styles` type. * Where necessary for the compiler, updated other types (mainly for `createStyleSheet` and `StyleSheet`. * Includes minor automated changes. React-JSS: * `createUseStyles` now expects type parameters for `Props` and `Theme`. * `data` in `useStyles` now expects the proper typed argument (`Props` with an optional `Theme`.) * Types are arranged to prevent unnecessary/confusing parameter shadowing. If the argument to `createUseStyles` is a function of `Theme`, then no properties (or nested properties) in the object that the function returns are permitted to define functions with access to `Theme`. * Updated types for `withStyles` (and related types) to be compatible with new changes. * Added several typed tests for `createUseStyles` and `withStyles` to ensure that everything behaves as expected.
fac9793 to
057f152
Compare
|
There was a line or 2 where some previous changes were accidentally reverted. My recent |
|
Can you please add to changelog whatever we have done here? eventually with hints what needs to be done in case of errors |
|
I can do that. Would you want me to update the changelog in this PR or in a separate one? |
|
Both works, if you want to create a separate - feel free |
|
Okay cool. I'll probably create a separate PR in that case. I'll try to add changelog updates today or tomorrow. |
|
Merged 🎉 Thank you everyone! |
|
Order of generic should be changed. Current is createUseStyles<C extends string = string, Props = unknown, Theme = Jss.Theme>should change to createUseStyles<Props = unknown, Theme = Jss.Theme,C extends string = string> |
|
Hi @hosseinmd. Originally, this PR had the order you suggested, but it was changed to the current ordering because it plays most nicely with TypeScript. Due to the nature of TypeScript's type inference, putting const useStyles = createUseStyles<MyProps>({ /* ... */ });
const classes = useStyles(props)would cause
|
|
I don't agree with you at all. C generically defined from inserted object to createUseStyle, and usually we don't need to specify C |
|
Friend, you're free to disagree. But if you closely read the PR, the comments, and the issues I mentioned in my last comment, you would understand that TypeScript will not work correctly if C isn't specified. Your response tells me that you did not closely examine the examples I gave nor the issues I linked. I can't help you beyond the linked issues and examples I provided (additional examples exist in the linked issues). Trust me, I ran through tons of headaches trying to figure this thing out. The current order is due to a limitation in TypeScript. |
This is not true. |
|
My application typescript is broken, and I have to define whole C and props, but we don't need to define C because that could be recognized from inserted object. |
|
I have to back old version |
|
@hosseinmd I'm unwilling to continue the conversation until you observe the issues I linked and the evidence I provided. I'm the one who created the PR, which -- as I mentioned -- started off as
Because |
|
I created a PR please review that work well |
|
I've updated react-jss and I'm now facing this issue: #1479 |
What Would You Like to Fix/Add?
This PR aims to ensure that the
createUseStyleshook has accurate TS intellisense forpropsandthemes. The details of the work can be found in the commit message. Note that as a result of cascading effects, this PR also improves the types for the deprecatedwithStylesHOC. This should satisfy #1273 and #1431.These are TypeScript changes only, as only these changes will be visible to the TypeScript users. These are the minimal changes necessary to improve the user experience for TS devs. Flow is separate and unrelated to the user, and I'm not so familiar with it, so it's simplest to add flow changes in a separate commit (if that's acceptable). (If someone else familiar with Flow could apply the changes, that would be helpful. I've already supplied the TS types, so it should be easy.)
Goals
createUseStyles/withStyles(ie. the object argument and the function argument).propsandthemethat returns a style object will not give type inference to nested functions.Propsis typically more necessary thanTheme.withStyles"lazy migration" in TS should be "sufficiently easy" ("not too complicated") to write given these changes. If not, these new types may need to be revisited. (This requires closely examining how well the HOC is defined, not just how well these new types are defined.)Caveats
props/data.createUseStyles<Theme>syntax, they will have to update their types. This is unfortunate, but not hard. And since TS has better intellisense whenNameis not specified, this shouldn't be a common concern.Unknowns / Concerns
any.Injss/src/index.d.ts, should all default usages ofJssStylebe updated to useJssStyle<any>in the context of these proposed changes?Extra Notes
createStyleSheetusesanyfor theData/Propstype because the data can be dynamically changed at any point.anyis safest.Todo