After going through all the information on String Based Enums in Typescript, I have yet to find a solution that fits my specific needs. These are the requirements I am looking for:
- Enums that offer code completion
- Enums that can be looped over
- No need to repeat elements
- String-based enums
The enum possibilities I've come across in Typescript so far include:
enum MyEnum {bla, blub}
: This does not support string-based functionality, making it difficult to read from JSON files...type MyEnum = 'bla' | 'blub'
: Not iterable and lacks code completion- Creating a custom
: Involves specifying elements twiceclass MyEnum { static get bla():string{return "bla"} ; static get blub():string{return "blub"}}
Considering these limitations, I have the following questions:
- Is there currently no way to fulfill all of these requirements simultaneously? If not, will this be achievable in the future?
- Why weren't Enums designed to be string-based?
- Has anyone encountered similar issues and how did you resolve them?