question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theme overrides : width does not exist on type CSSProperties

See original GitHub issue

Using createMuiTheme I override the MuiCard, setting a custom width and height, in this way.

const theme = createMuiTheme({
  palette: {
    type: 'light',
    primary: {
      main: primaryColor,
    },
    secondary: {
      main: secondaryColor,
    },
    fallback: {
      main: fallback,
    },
    fog: {
      main: fog,
    },
  },
  overrides: {
    MuiCard: {
      root: {
        width: 300,
        height: 276,
        margin: 15,
        [breakpoints.down('sm')]: {
          margin: 5,
        },
      },
    },
  },
  props: {
    MuiSkeleton: {
      animation: 'pulse',
    },
    MuiAvatar: {
      variant: 'rounded',
    },
  },
})

The component take the good dimensions. The problem comes when I try to access these values in the style of other components.

export const useStyle = makeStyles((theme: Theme) =>
  createStyles({
    cardSkeleton: {
      width: theme.overrides?.MuiCard?.root?.width ?? 300,
      height: theme.overrides?.MuiCard?.root?.height ?? 276,
      margin: 15,
      [theme.breakpoints.down('sm')]: {
        margin: 5,
      },
    },
  }),
)

I have this error for width and height : Property 'width' does not exist on type 'CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>'. Property 'width' does not exist on type 'PropsFunc<{}, CreateCSSProperties<{}>>'.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Your Environment 🌎

Tech Version
Material-UI v4.10.2
React 16.11.0
Browser Chrome
TypeScript 3.8.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ukriscommented, Jul 9, 2020

I’ve created a Github repo based on your code sandbox. https://github.com/ukris/material-ui-theme-overrides

master corresponds to material-UI - 4.9.11 and branches 4.11.0 and 5.0.0.alpha2 respectively.

for some reason in your case, all version works with the changes

There is one caveat: // @ts-ignore const root:CSSProperties = theme.overrides?.MuiCard?.root

if // @ts-ignore is unacceptable, then I guess u can do a conditional check, and return two different objects. or have theme: any as some solutions seemed to allude - which I think is not an acceptable solution. Below is conditional check without @ts-ignore

 const rt = theme.overrides?.MuiCard?.root
  if (!rt) {
    return createStyles({
      constainer: {
        position: 'relative',
        backgroundColor: theme.palette.fog.main,
      },
    })
  }
  const root =  rt as CSSProperties
  return createStyles({
    constainer: {
      position: 'relative',
      width: root?.width,
      height: root?.height, 
      margin : root?.margin,
      backgroundColor: theme.palette.fog.main,
    },
  })```



0reactions
RobelTeklecommented, Jul 7, 2020

Tried to downgrade to 4.9.10 I still have the error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theme overrides : width does not exist on type CSSProperties ...
Using createMuiTheme I override the MuiCard, setting a custom width and height, in this way. const theme = createMuiTheme({ palette: { type: ...
Read more >
Typescript error says property does not exist on type
Type 'Theme' is missing the following properties from type 'Theme': mixins, palette, shadows, transitions, and 6 more. I tried like this too:
Read more >
CSSProperties - typescript
The column-width CSS property specifies the ideal column width in a multi-column layout. The container will have as many columns as can fit...
Read more >
The sx prop - MUI System
The sx prop is a shortcut for defining custom styles that has access to the theme. The sx prop lets you work with...
Read more >
width - CSS: Cascading Style Sheets - MDN Web Docs
Ensure that elements set with a width aren't truncated and/or don't obscure other content when the page is zoomed to increase text size....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found