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
makeStyles typescript issue when using function type attribute on 4.11.1 #23706
Comments
Support for TypeScript 4.1 shouldn't have been released since we decided to not release features for 4.x anymore. Seems like this feature came with new bugs which is exactly the reason why you usually don't release features for LTS releases. Sorry about that. I recommend you roll back to 4.11.0. |
@eps1lon What do you think about this alternative read?
|
@atnpcg Do you have a reproduction on Codesandbox? It would help :) |
If you find someone to do it, sure. I don't have time for it. |
hi @oliviertassinari here is a sandbox with the new version: |
@atnpcg Thanks. Are you should about the previous TypeScript logic? I was expecting to see: const useStyles = makeStyles(() => ({
root: (props: TestProps) => {
return {
display: "flex"
};
},
test: (props: TestProps) => {
return {
display: "flex"
};
}
})); https://codesandbox.io/s/dark-microservice-kpivc?file=/src/App.tsx:243-443 Why use |
@oliviertassinari, of course it can be fixed by changing the code, the code I provided is jut a minimal example, the code I detected the issue was in a more complex project with more complex props. |
If wasn't meant to be a breaking change. I guess want to comes to TypeScript, there isn't any semver? My question would be more about. Is your example correct? I don't really understand the motivation for using different types for the props. Could it actually surface a behavior that was previously wrong? |
@oliviertassinari , that's a good question!, I think we are using pick all over our project, thinking that we don't need all the props of a given type for each function. |
I think this happens with any function in const useStyles = makeStyles({
wrapper: {
display: "flex",
alignItems: "center",
},
icon: {
marginRight: 16,
minWidth: (size: number) => size,
width: (size: number) => size,
height: (size: number) => size,
},
}); The TS error is:
|
@maccuaa The argument of makeStyles() is designed to be used as an object. |
Ah ok. Changing it to this fixed the issue: const useStyles = makeStyles({
icon: {
marginRight: 16,
minWidth: (props: Props) => props.size,
width: (props: Props) => props.size,
height: (props: Props) => props.size,
},
}); But to @atnpcg's point, my first snippet worked fine in 4.11.0 but broke in 4.11.1 which is not something you expect to happen in a patch release. But I guess the original implementation was wrong so the fix in 4.11.1 breaks everyone who's been using it wrong this entire time 😛 |
Closing as the change while breaking was surfacing incorrect usages, at least, not how we designed the API to be used. Thanks for raising! |
after updating to material-ui-core 4.11.1
I have a typescript error when using makeStyles using attributes in a function type
Current Behavior 😯
I get a Typescript error saying props are not compatible with props
Expected Behavior 🤔
should not have any errors
I couldn't' configure the playground with recent versions. but you can copy paste the code to version 4.11.1 and you will see the typescript error.
on version 4.11.0 is not happening
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQokscA3nXHAPSdwwAWWOLhKQAdllEx0ATwgBXOHNRYAJnQC+cIiXIABEMhhYowZABsAtHOCdhlMg3DR4LOAYDWWAMoxpZrOia2qRk+obGppbWttBYnKi+-qi0dKm+YIIAKgEwAArEYOgAvKzsHHBgBQCMAFxwCSaiAOb05RUFAEx1DcDNreWVEGAAzAD83TCNLRr0dMKiCYrKPn4BcCUe3okBABQ7AJTrAHxwO2xtxBAwdTuDhXW5wLjuADzZCflDqAA05HdVZDgAB8-p0yEdDkUTuc2uVKDA5FBRKVYai4CpgKgwGZkNI6mQCP4AB5kb5lVHqfocdRk8m8HI3O6oB5PV7vPIFH6gobDcGQ6F0i5YBFIlFotoYrE4vHkQlYElk8WUuk0jT7fb0AhyUT4YAQZEAESwIAgBzF3DgAE15FAhBAVFgNEA
The text was updated successfully, but these errors were encountered: