【发布时间】:2021-07-18 14:42:57
【问题描述】:
我正在使用带有 TypeScript 的 Material UI 并希望为我的主题添加自定义颜色。一切正常,除了显示下一条消息的 VSCode linter。
Type '{ tan: string; lightRed: string; red: string; offBlack: string; white: string; }' is not assignable to type 'Partial<CommonColors>'.
Object literal may only specify known properties, and 'tan' does not exist in type 'Partial<CommonColors>'.
在开发和构建方面工作正常,唯一的抱怨是错误消息。我添加了一个自定义类型来尝试解决,但它不起作用。
const theme = createTheme({
palette: {
common: {
tan,
lightRed,
red,
offBlack,
white,
},
},
});
import {
PaletteOptions,
CommonColors,
} from '@material-ui/core/styles/createPalette';
interface CustomColors extends CommonColors {
tan: string?;
lightRed: string;
red: string;
offBlack: string;
}
declare module '@material-ui/core/styles/createPalette' {
export interface PaletteOptions {
common: CustomColors;
}
}
我添加到 tsconfig.json 文件中。棕褐色、红色和其他值被声明为字符串。关于如何解决这个问题的任何线索?提前致谢。
【问题讨论】:
标签: reactjs typescript material-ui