π Search Terms
infinity nan enum string
β
Viability Checklist
β Suggestion
Allow the usage of Infinity, -Infinity, and NaN as key names in a string enum.
I understand the reasoning behind disallowing numeric names as enum keys, as they can cause conflicts with reverse mapping.
However, in the case of a string enum where every value is a string, reverse mapping is not applied. Therefore, it does not make sense to disallow numeric names in this scenario.
π Motivating Example
enum SomeEnum {
Infinity = 1, // This should fail!
Apple = Number.POSITIVE_INFINITY,
}
enum MinecraftEnchantmentTypes {
Infinity = 'infinity', // This should pass!
Unbreaking = 'unbreaking'
}
π» Use Cases
-
What do you want to use this for?
To maintain compatibility with existing code.
-
What shortcomings exist with current approaches?
Please refer to the suggestion provided.
-
What workarounds are you using in the meantime?
Currently, there are no workarounds available except renaming enum members, which would introduce breaking changes.
π Search Terms
infinity nan enum string
β Viability Checklist
β Suggestion
Allow the usage of
Infinity,-Infinity, andNaNas key names in a string enum.I understand the reasoning behind disallowing numeric names as enum keys, as they can cause conflicts with reverse mapping.
However, in the case of a string enum where every value is a string, reverse mapping is not applied. Therefore, it does not make sense to disallow numeric names in this scenario.
π Motivating Example
π» Use Cases
What do you want to use this for?
To maintain compatibility with existing code.
What shortcomings exist with current approaches?
Please refer to the suggestion provided.
What workarounds are you using in the meantime?
Currently, there are no workarounds available except renaming enum members, which would introduce breaking changes.