Skip to content

MUI v7 color palette extension problem with TypeScript when using new colors on a Button #45787

Closed
@CzechCoder

Description

@CzechCoder

I created a new color palette I want to use on a Button as in accordance to the documentation:

const theme = createTheme({
palette: {
customRed: {
main: "#ff1100",
light: "#f75348",
dark: "#ba1f14",
contrastText: "#FFF",
},
}
})

Then extended TypeScript declarations:

declare module "@mui/material/styles" {
interface Palette {
customRed: Palette["primary"];
}

interface PaletteOptions {
customRed?: PaletteOptions["primary"];
}

But then I get a TS error when using the new color palette on a Button (Type "customRed" is not assignable to type):

Button

It should work and it used to work for me in the past, but now it doesn't. Any ideas on how to expand my color palette for buttons?

Search keywords:

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: buttonThis is the name of the generic UI component, not the React module!typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions