Skip to content

Suggestion: Iterate through Enum values #4753

Closed
@aciccarello

Description

@aciccarello

Enums currently get outputted to an object with two-way mapping of numbers. This makes it hard to iterate through the names (or values) of an enum. A method on the enum object to get the keys of the enum would allow iterating.

See this StackOverflow question for a use case of iterating. (And use of a regular expression for filtering).

Possible Solutions:

  • Add a length property (for enums with default index) too limited
  • Function on enum type filtering keys looking for numbers (could break with other index types)
  • Add a function with the keys hard coded when compiling

Complications:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions