score:4

Accepted answer

parentColor is any, not a keyof Palette. To remove the error, you need to assert it with the correct type:

// "primary" | "secondary" | "error" | "warning" | "info" | "success"
type PaletteKey = keyof {
  [Key in keyof Palette as Palette[Key] extends PaletteColor ? Key : never]: true;
}

// "light" | "dark" | "main" | "contrastText"
type PaletteColorKey = keyof PaletteColor

theme.palette[parentColor as PaletteColorKey][childColor as PaletteColorKey]

Related Query

More Query from same tag