Closed
Description
Although enums are both numbers and strings, it's not possible to use a type like this:
enum Values {
A, B, C
}
type ValuesConstraint = {
[index: Values]: string; // An index signature parameter type must be 'string' or 'number'
}
const Mapped: ValuesConstraint = {
[Values.A]: 'Alpha',
[Values.B]: 'Beta',
[Values.C]: 'Gamma'
}
const f = Mapped[Values.C] // f: any
Tried to use in
as in [index in Values]
but it says Type 'Values' is not assignable to type 'string'
. Trying to use a type ValuesType = Values.A | Values.B | Values.C
also doesn't work, is there any workaround?