Let's say I have a simple enum
enum MyEnum {
a,
b,
c
}
Mapping the enum into a key value const is simple:
type A<V> = { [k in MyEnum]: V };
const testA: A<string> = {
[MyEnum.a]: '',
[MyEnum.b]: '',
[MyEnum.c]: ''
};
The problem starts when I am trying to pass the enum as a generic type:
type B1<T, V> = { [k in T]: V } // that won't work
const testB: A<MyEnum , string> = { ... } // usage
I tried few approaches ideas in this play-ground
There are some similar question (listed bellow) but I still got the feeling that in this particular example if the first option (type A<V> = { [k in MyEnum]: V };
) is possible the other options should be too (type B1<T, V> =
).
Mapping Enum to Type of keys or values
is-it-possible-to-allow-literal-string-values-with-typescripts-enum-type