I'm using TypeScript, where the enums are just a combined object of name-to-number and number-to-name. The implementation looks vaguely like this:
ServerEnum = {
0: "FirstServer",
1: "SecondServer",
"FirstServer": 0,
"SecondServer": 1
}
And I'm using an enum as the key in an object. And it's really convenient a lot of the time, because I have one of those enum values hanging around most of the time.
{
[ServerEnum.FirstServer]: {...},
[ServerEnum.SecondServer]: {...}
}
It's great, except in two cases:
Object.keys(), Object.values(), and Object.entries() will all return a string key, so my enum value of 1 gets coerced into "1".
I also end up sticking that enum into the URL, where it should be the string-value rather than the number-value.
So for 1), I'm using parseInt(enumThing) as ServerEnum in my iterators.
And for 2), I'm doing a lot of ServerEnum[enumAsNumber] and ServerEnum[enumAsString]. I should probably switch from Object to Map, but , and Map's iteration API is a bit uglier.