-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
scope: stylesSpecific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.typescript
Description
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
When using typescript 3.5, code that worked in typescript 3.4 is now rejected:
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
paddingTop: theme.spacing(0.5),
paddingBottom: theme.spacing(0.5),
},
})
);
export default function MyComponent(props: any) {
const { root } = useStyles(); // ERROR: Expected 1 arguments, got 0
return <div className={root}>{props.children}</div>;
}Expected Behavior 🤔
useStyles() should work with 0 arguments
The problem seems to come from a change in something that's commented on in makeStyles.d.ts:
* If a style callback is given with `theme => stylesOfTheme` then typescript
* infers `Props` to `any`.
* If a static object is given with { ...members } then typescript infers `Props`
* to `{}`.
*
* So we require no props in `useStyles` if `Props` in `makeStyles(styles)` is
* inferred to either `any` or `{}`
In typescript 3.5, Props is inferred to object 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 🌎
"@material-ui/core": "^4.0.1",
"@material-ui/icons": "^4.0.1",
"@material-ui/styles": "^4.0.1",
"typescript": "^3.5.1"
eps1lon, gurkerl83, alexey-gorshkov and durdenx
Metadata
Metadata
Assignees
Labels
scope: stylesSpecific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.typescript