I have the following code:
enum MY_ENUM {
A,
B,
C
}
type MY_TYPE = {
field: MY_ENUM
}
// Error: Type '{ field: string; }[]' is not assignable to type 'MY_TYPE[]'.
const myArray: MY_TYPE[] = Object.keys(MY_ENUM).map(key => {
return {
field: key, // key is a string, but I want it to be MY_ENUM
}
})
It gives an error on myArray
, saying string is not assignable to type 'MY_TYPE'.`, so how do I get the enum typed key instead of string? Or in another word, how can I iterate enum, gets the actual enum typed key but not its string representation?