Long story short, typescript complains the missing property classes on every material-ui component. In other words, Typescript forces the classes property to be existed in almost every material-ui components. Here is error message during webpack compiling using ts-loader,
I have following codes,
Header.tsx
import AppBar from 'material-ui/AppBar';
import * as React from 'react';
import { withStyles } from 'material-ui/styles/index';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/Typography';
const decorate = withStyles((theme) => ({
header: {
paddingTop: theme.spacing.unit,
width: '100%',
},
}));
const AppBarTypographyStyle = {
color: 'white',
fontSize: '1.6rem',
};
const Header = decorate(({classes}) => (
<header>
<AppBar position="static" classes={{root: classes.header}}>
<Toolbar>
<Typography style={AppBarTypographyStyle} classes={{}} color="inherit" type="title">
OLIVE
</Typography>
</Toolbar>
</AppBar>
</header>
));
export default Header;
And I have error for Toolbar with following messages
TS2322: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ToolbarProps & { children?: ReactNode; }'.
Type '{ children: Element; }' is not assignable to type 'ToolbarProps'.
Property 'classes' is missing in type '{ children: Element; }'
For AppBar and Typography I don't receive error as i added classes property with my styles defined in the function decorator and an empty object; However it is not possible to JUST USE style & className properties
<AppBar position="static" style={exampleStyleObj} className={exampleClass} >
I follows the styling approach using withStyle decorator from material-ui doc
CSS IN JS & Over
https://material-ui-next.com/customization/css-in-js/Overrides
https://material-ui-next.com/customization/overrides/Typescript Material-UI guides
https://material-ui-next.com/guides/typescript/
I am using, [email protected] [email protected]
I have checked if there are same issues and answer elsewhere and even checked the material-ui source codes and found the following,
/**
* All standard components exposed by `material-ui` are `StyledComponents` with
* certain `classes`, on which one can also set a top-level `className` and inline
* `style`.
*/
export type StandardProps<C, ClassKey extends string, Removals extends keyof C = never> =
& Omit<C & { classes: any }, 'classes' | Removals>
& StyledComponentProps<ClassKey>
& {
className?: string;
style?: Partial<React.CSSProperties>;
}
The StandardProps is what most ComponentProps interface extends from (For example, AppBarProps). However so far i have not much luck for solving these.
Please help!
[email protected]and[email protected]. What's more it should not be necessary as you say to provide an emptyclassesprop to any Material UI component... that was the case with some older versions of the typings, but not any more. Are you sure you're using the latest version?[email protected]to[email protected]and it successfully compile. However i would like to hold this question a bit longer just in case similar error appears again down the road.