-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Typescript 3.5 causes makeStyles problem #15942
Comments
3.5 announcement is scheduled for tomorrow (holiday for me). Will have a look on friday and see what changed. |
3.5 was actually released today; I guess they changed. No hurry of course, but |
But I hope you understand that the latest breaking release will always take some time to adjust to. I recommend you never upgrade to the latest typescript versions in production. Releases in typescript don't follow semantic versioning. Minor releases are almost always breaking. |
I do understand. I upgraded to typescript 3.5.1 on a separate branch of my app, saw this issue, and switched back to my main branch. My app remains on 3.4.5 and can stay there for the foreseeable future. I wrote it up right away because, might as well have the information available for anyone who is interesting in looking into it. |
Just a little digging I've done. Issue seems to be with unknown extends T ? false : true Simply testing this out with the default value of type Test = unknown extends {} ? false : true
Not sure what the right fix would be. I assume it's due to microsoft/TypeScript#30637 (Also the first listed "Breaking change" on https://devblogs.microsoft.com/typescript/announcing-typescript-3-5/) |
I've got exactly the same issue. Workaround is to just pass in an empty object, so it becomes useStyles({}) |
Well it's a breaking change. We now have to figure out how to support to incompatible versions of typescript. I think that's where typeVersions comes in. I hope this doesn't require a complete fork but only one for how we determine if a given |
@nmain Since you're on that version of typescript you don't need to specify the theme type and you can omit |
Actually I was wrong, it does solve the issue. You didn't specify that you're importing from Fixed in #15990 |
I'm using the latest version (4.0.2) and [email protected] and the issue seems to be still there. Am I the only one still affected? |
No, I'm also having the same error with these versions. |
@HorusGoul @PieterBoeren Could you provide an example the reproduces the problem? The one from the OP doesn't cause issues. Also, since you're using a newer version of typescript you can omit |
I use this syntax (which fails): const useStyles = makeStyles(() => {
return {
root: {
backgroundColor: 'red',
}
};
}); However, it works when using: const useStyles2 = makeStyles({
root: {
backgroundColor: 'red',
},
}); But I like the first syntax (which was working before typescript 3.5), because you can then add the theme object very quickly when needed, but this also fails now: makeStyles((theme: Theme) => ...) Just to be clear: I don't use "createStyles" at all. |
@merceyz I'm using the same syntax const useStyles = makeStyles(theme => ({
...
}); And just to clarify, I'm importing |
Provide a codesandbox please, I can't reproduce with those snippets. |
Can't reproduce it in a CodeSandbox, but based on a standard app create via "strictPropertyInitialization": false,
"strictNullChecks": false to the tsconfig breaks it. Removing the two lines (or setting them to "true") and it works... |
Thank you, I can reproduce it now. Working on a fix |
@PieterBoeren Your issue isn't the same as what this issue was for. See #16088 (comment) TL;DR: material-ui doesn't support |
@merceyz Do you know what the use case is for checking unknown extends T ? false : true in |
Remove it and run the test. Should fail because it considers
|
Yeah I just meant what's the practical use case for that. Obviously if this only supports Basically:
Again, just wondering, not saying anything is wrong. |
Good question. I think my thinking just went (back in 3.3): "no inferrable means There's a case to be made to also accept 0 arguments if the expected type is My problem currently is that the types and tests between core/styles and styles are fractured so I'm extra careful about changes. And if those changes only serve unsupported environments I have to defer that for now. But once we resolve this we can definitely revisit that. |
Any updates? |
@sashankaryal The original issue was fixed in 4.0.2. If the issue still persists in later versions please open a separate issue and fill out the template. |
Current Behavior 😯
When using typescript 3.5, code that worked in typescript 3.4 is now rejected:
Expected Behavior 🤔
useStyles()
should work with 0 argumentsThe problem seems to come from a change in something that's commented on in
makeStyles.d.ts
:In typescript 3.5,
Props
is inferred toobject
now.Steps to Reproduce 🕹
I cannot reproduce this on codesandbox.io right now. I suspect it's because I can't get the right typescript version there. I can however reproduce this from a new empty
create-react-app
, using just the packages below and the code above.Your Environment 🌎
The text was updated successfully, but these errors were encountered: