[typescript] `makeStyles - 'Styles<Theme, StyleProps, "root"...` error
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
I use “@material-ui/core”: “4.11.3”
I have a Text.tsx component and its styles are in Text.styles.tsx. I use the makeStyles function to expend Mui styles.
Text.styles.tsx
import { makeStyles, Theme } from '@material-ui/core';
interface StyleProps {
marginRight: number;
marginLeft: number;
}
const useStyles = makeStyles((theme: Theme) => {
return {
root: {
marginRight: (props: StyleProps) => theme.spacing(props.marginRight),
marginLeft: (props: StyleProps) => theme.spacing(props.marginLeft),
},
weightBold: {
fontWeight: theme.typography.fontWeightBold,
},
weightSemiBold: {
fontWeight: theme.typography.fontWeightMedium,
},
weightRegular: {
fontWeight: theme.typography.fontWeightRegular,
},
colorWhite: {
color: theme.palette.background.default,
},
underlinedText: {
textDecoration: 'underline',
},
notUnderlinedText: {
textDecoration: 'none',
},
};
});
export default useStyles;
Expected behavior 🤔
The error was not present before yesterday, so I am expecting it not to be there since I have not changed any dependecy.
Steps to reproduce 🕹
Steps:
- delete node_modules and yarn.lock
- yarn install
- yarn start
Context 🔦
package.json
The dependencies I use of MUI are:
"@material-ui/core": "4.11.3",
"@material-ui/icons": "4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60",
Your environment 🌎
`npx @mui/envinfo`
System:
OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
Binaries:
Node: 14.18.1 - /usr/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.15 - /usr/bin/npm
Browsers:
Chrome: 96.0.4664.110
Firefox: 95.0.1
npmPackages:
@types/react: ^17.0.0 => 17.0.38
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
typescript: ^4.1.2 => 4.5.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
makeStyles - 'Styles<Theme, StyleProps, "root" - Stack Overflow
I think the problem is here, because I use the same stuffs and it works fine. The path where to import is slightly...
Read more >Material-UI makeStyles function causes compilation error
IssueIn the React + TypeScript + Material-UI project, using the makeStyles method, the code is as follows:import { makeStyles, ...
Read more >@material-ui/styles | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >Material-UI: .../makeStyles/makeStyles.spec.tsx | Fossies
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TSX (TypeScript with React) source...
Read more >TypeScript React with Material-ui's makeStyles/withStyles ...
FC<Props> = ({ value, children, ...styleProps }) => { const classes = useStyles(styleProps); return ( <div className={classes.root}> <strong ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ended up adding
fontWeight: theme.typography.fontWeightMedium as number
+ thecreateStyles
at from the post above to fix my issues. I was going to migrate to V5 but that seemed like a bad move all together.@ypresto
I can find it in my
yarn.lock
, but how do I know which dependency in package.json to update?I do not generally push my
yarn.lock
, so I do not think I have to change it manually. Also it seems I am usingcsstype@^3.0.2
andcsstype@^2.5.2
in myyarn.lock
, notcsstype 3.0.9 -> 3.0.10