Material-ui: `CreateCSSProperties` is not assignable to `CSSProperties` after upgrading to `4.0.2`

Created on 13 Jun 2019  路  3Comments  路  Source: mui-org/material-ui

I found CreateCSSProperties is not assignable to CSSProperties after upgrading to 4.0.2.
Below is my code:

import { withStyles, createStyles } from '@material-ui/core/styles';
const styles = createStyles({
  logo: {
    position: 'fixed',
    top: 0,
    height: '4rem',
    backgroundColor: '#28064A',
    width: '100%',
    alignItems: 'center',
    paddingLeft: '0.5rem',
    zIndex: 1
  }
}

...
   <MenuIcon styles={styles.logo} />
...
 ```

The `styles` of `MenuIcon` is type of `styles?: React.CSSProperties;`. I get this error:

TS2322: Type 'CreateCSSProperties<{}> | ((props: {}) => CreateCSSProperties<{}>)' is not assignable to type 'CSSProperties | undefined'.
Type 'CreateCSSProperties<{}>' is not assignable to type 'CSSProperties'
```

It seems that after 4.0.2 createStyles returns a type which is not compatible with React.CSSProperties. Is there a quick way to fix it?

typescript

Most helpful comment

I was thinking more of styles.logo as CSSProperties but yeah, you can do that as well

All 3 comments

Working on a fix.

Is there a quick way to fix it?

Cast the result from createStyles would be the easiest

so you mean using as any?

I was thinking more of styles.logo as CSSProperties but yeah, you can do that as well

Was this page helpful?
0 / 5 - 0 ratings

Related issues

revskill10 picture revskill10  路  3Comments

newoga picture newoga  路  3Comments

rbozan picture rbozan  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

mb-copart picture mb-copart  路  3Comments