You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
enumSomeEnum{Infinity=1,// This should fail!Apple=Number.POSITIVE_INFINITY,}enumMinecraftEnchantmentTypes{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.
The text was updated successfully, but these errors were encountered:
enumE{Infinity="boop",blah=1/0,}console.log(E.Infinity);// prints "blah", not "boop"!
I other words, we need to keep the keys and reverse-mapping keys disjoint so one doesn't stomp on the other.
There's basically two ways of relaxing this:
numerically named string enum members are allowed if all members of an enum are string-based
numerically named string enum members are allowed if no other enum member contributes a conflicting reverse mapping
(1) is just a heavier restriction of (2) because it'll be vacuously true - there will never be any conflicting reverse mappings because there won't be any to begin with on an all-string enum.
π Search Terms
infinity nan enum string
β Viability Checklist
β Suggestion
Allow the usage of
Infinity
,-Infinity
, andNaN
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
π» 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.
The text was updated successfully, but these errors were encountered: