简体   繁体   English

调色板中的 MUI 自定义命名选项 - 类型“TypeBackground”上不存在属性“primary”

[英]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.

相关问题 “主题”类型上不存在 MUI 属性“调色板” - MUI Property 'palette' does not exist on type 'Theme' “AppComponent”类型上不存在属性“alertService”和“options” - Property 'alertService' and 'options' does not exist on type 'AppComponent' 无法声明多个自定义命名属性 TypeScript MUI v5 Palette - Unable to declare multiple custom named properties TypeScript MUI v5 Palette MUI v5 属性“fullWidth”在类型“IntrinsicAttributes &amp; { theme: Theme;”上不存在。 } &amp; { 孩子?:ReactNode; }&#39;。 TS2322 - MUI v5 Property 'fullWidth' does not exist on type 'IntrinsicAttributes & { theme: Theme; } & { children?: ReactNode; }'. TS2322 使用自定义类型定义时,类型上不存在属性 - Property does not exist on type when using custom type definition TypeScript 如何强制执行多种类型选项,类型“Y”上不存在属性“X” - TypeScript how to enforce a type of multiple type options, Property 'X' does not exist on type 'Y' 类型上不存在属性但属性存在 - Property does not exist on type But property exist 无法为 mui 组件使用自定义调色板 - Unable to use custom palette for mui component React 属性在类型“IntrinsicAttributes”(自定义钩子)上不存在 - React Property does not exist on type 'IntrinsicAttributes' (custom hook) myworkout:类型上不存在属性 - myworkout: Property does not exist on type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM