[英]MUI Custom named options in palette - Property 'primary' does not exist on type 'TypeBackground'
I am trying to extend the MUI palette so I can use my own named properties with the following code:我正在尝试扩展 MUI 调色板,以便可以通过以下代码使用我自己的命名属性:
declare module '@mui/material/styles' {
interface Palette {
border: Palette['primary']
background: Palette['primary']
}
// allow configuration using `createTheme`
interface PaletteOptions {
border?: PaletteOptions['primary']
background?: PaletteOptions['primary']
}
}
border
works without issues, however since trying to add a new background it does complain about this one. border
可以正常工作,但是由于尝试添加新背景,它确实对此有所抱怨。
Full Error:完全错误:
Property 'primary' does not exist on type 'TypeBackground'. TS2339
8 |
9 | const DocumentUploadContainer = styled('div')`
> 10 | color: ${props => props.theme.palette.background.primary};
| ^
11 | `
12 | export const Documents = () => {
13 | return (
You can check in file createPalette.d.ts of mui.您可以签入 mui 的文件 createPalette.d.ts。 Because
background
is already in interface PaletteOptions
, (as you can see here)因为
background
已经在interface PaletteOptions
中,(如您在此处看到的)
export interface PaletteOptions {
primary?: PaletteColorOptions;
secondary?: PaletteColorOptions;
error?: PaletteColorOptions;
warning?: PaletteColorOptions;
info?: PaletteColorOptions;
success?: PaletteColorOptions;
mode?: PaletteMode;
tonalOffset?: PaletteTonalOffset;
contrastThreshold?: number;
common?: Partial<CommonColors>;
grey?: ColorPartial;
text?: Partial<TypeText>;
divider?: string;
action?: Partial<TypeAction>;
background?: Partial<TypeBackground>;
getContrastText?: (background: string) => string;
}
export interface TypeBackground {
default: string;
paper: string;
}
Hence, you cannot use module augmentation to override it like this.因此,您不能像这样使用模块扩充来覆盖它。 Just use another name.
只需使用另一个名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.