Sometimes, we want to map Typescript enums.
In this article, we’ll look at how to map Typescript enums.
How to map Typescript enums?
To map Typescript enums, we get the keys and map them.
For instance, we write
const mapped = (Object.keys(MyEnum) as Array<keyof typeof MyEnum>).map(
(key) => {
//...
}
);
to call Object.keys
with MyEnum
to return an array of enum keys.
Then we call map
with a callback to return an array with the mapped entries.
Conclusion
To map Typescript enums, we get the keys and map them.