Struggling with TypeScript and Material UI integration, I'm puzzled by the issue of passing an object to createMuiTheme.
This code snippet works perfectly:
const themeConfig = createMuiTheme({
palette: {
primary: green,
secondary: purple,
type: 'light'
}
});
But, this following code does not work (!):
const themeObject = {
palette: {
primary: green,
secondary: purple,
type: 'light'
}
};
const themeConfig = createMuiTheme(themeObject);
An error message states that 'palette.type = 'light' (string)' is not assignable to 'palette.type = 'light' | 'dark' | undefined'. This error is truly perplexing.
Argument of type '{ palette: { primary: { 50: "#e8f5e9"; 100: "#c8e6c9"; 200: "#a5d6a7"; 300: "#81c784"; 400: "#66bb6a"; 500: "#4caf50"; 600: "#43a047"; 700: "#388e3c"; 800: "#2e7d32"; 900: "#1b5e20"; A100: "#b9f6ca"; A200: "#69f0ae"; A400: "#00e676"; A700: "#00c853"; }; secondary: { ...; }; type: string; }; }' is not assignable to parameter of type 'ThemeOptions'.
The types of 'palette.type' are incompatible between these types.
Type 'string' is not assignable to type '"light" | "dark" | undefined'.ts(2345)