Skip to content

Allow Infinity, -Infinity and NaN as an enum key name for string enumΒ #57845

Closed
@XeroAlpha

Description

@XeroAlpha

πŸ” 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

  1. What do you want to use this for?
    To maintain compatibility with existing code.

  2. What shortcomings exist with current approaches?
    Please refer to the suggestion provided.

  3. What workarounds are you using in the meantime?
    Currently, there are no workarounds available except renaming enum members, which would introduce breaking changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions