-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme overrides : width does not exist on type CSSProperties #21650
Comments
I believe we cover this in https://material-ui.com/guides/typescript/#customization-of-theme, you need to tell TypeScript the theme has changed. |
Hi @oliviertassinari thanks for your answer. Following you recommendation I modified the theme type. I'm using cra, so all declaration are in the // / <reference types="react-scripts" />
import { Palette } from '@material-ui/core/styles/createPalette'
import { Theme } from '@material-ui/core/styles/createMuiTheme'
import React from 'react'
declare module '@material-ui/core/styles/createPalette' {
interface Palette {
fallback: Palette['primary']
fog: Palette['primary']
}
interface PaletteOptions {
fallback: PaletteOptions['primary']
fog: PaletteOptions['primary']
}
}
declare module '@material-ui/core/styles/createMuiTheme' {
interface Theme {
overrides: {
MuiCard: {
root: {
width: React.CSSProperties['width']
height: React.CSSProperties['height']
margin: React.CSSProperties['margin']
}
}
}
}
interface ThemeOptions {
overrides: {
MuiCard: {
root: {
width: React.CSSProperties['width']
height: React.CSSProperties['height']
margin: React.CSSProperties['margin']
}
}
}
}
} |
@RobelTekle Could you share a complete repro? This would help a lot identifying the issue. |
Hi @eps1lon, the project is in a private repo. I tried to create an example in codesandbox |
Same here. Typescript material UI with custom theme worked in 4.9.11. Broke after upgrading. |
Tried to downgrade to 4.9.10 I still have the error |
I've created a Github repo based on your code sandbox. master corresponds to material-UI - 4.9.11 for some reason in your case, all version works with the changes There is one caveat: 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.
|
This looks like v4 issue, we are no longer work on it. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @RobelTekle How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Using
createMuiTheme
I override theMuiCard
, setting a customwidth
andheight
, in this way.The component take the good dimensions.
The problem comes when I try to access these values in the style of other components.
I have this error for
width
andheight
:Property 'width' does not exist on type 'CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>'. Property 'width' does not exist on type 'PropsFunc<{}, CreateCSSProperties<{}>>'.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: