Can I rely on the ordering shown in the following example:
https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
That is, when there are two enums with the same value, the latter one "wins."
For context, my project currently has enums like so:
enum Foo {
a = 0,
b,
c,
MIN_VALUE = 0,
MAX_VALUE = 2,
}
This makes it problematic when accessing the values using the reverse mapping, because Foo[Foo.a] would yield "MIN_VALUE," instead of the desired "a." I'd like to try to fix this by reordering it to:
enum Foo {
MIN_VALUE = 0,
MAX_VALUE = 2,
a = 0,
b,
c,
}
But I'm not sure if I can depend on this behaviour. If there are other solutions to this problem I'd love to hear about it too! Thanks!
How TypeScript enums work