TypeScript总是抱怨调色板中缺少某些属性。如果我添加//@ts-ignore
,我的应用程序就能正常工作,但我显然想避免这样做。我对TypeScript还很陌生,以下是我尝试的内容。
import createMuiTheme, { ThemeOptions, Theme } from '@material-ui/core/styles/createMuiTheme';
import { PaletteOptions } from '@material-ui/core/styles/createPalette';
interface IPaletteOptions extends PaletteOptions {
chip: {
color: string,
expandIcon: {
background: string,
color: string,
},
},
}
interface ITheme extends Theme {
palette: IPaletteOptions,
}
const theme: ITheme = createMuiTheme({
typography: {
fontWeightMedium: 600,
fontFamily: ['Open Sans', 'Arial', 'sans-serif'].join(','),
},
palette: {
primary: {
main: '#43C099',
},
secondary: {
main: '#7AF3CA',
},
chip: {
color: '#C2C3C6',
expandIcon: {
background: '#808183',
color: '#FFFFFF',
},
},
},
} as ThemeOptions);
这会抛出一个错误,
Type 'Theme' is not assignable to type 'ITheme'.
Types of property 'palette' are incompatible.
Property 'chip' is missing in type 'Palette' but required in type 'IPaletteOptions
这个错误让我感到困惑,因为我没有在任何地方使用类型 Palette
。
我该如何正确地扩展调色板?