My custom type is called Color
,
type Color = 'yellow' | 'red' | 'orange'
In addition, I created an object with the interface named ColorSetting
.
interface ColorSetting {
id: string
yellow?: boolean
red?: boolean
orange?: boolean
}
I aimed to simplify the interface ColorSetting
by using the type Color
.
This simplified code looks like this:
interface ColorSetting {
id: string
[k in Color]?: boolean
}
However, I encountered an error stating that
A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.
What would be the correct way to utilize a string literal type within an interface?