So I've read all the posts on String Based Enums in Typescript, but I couldn't find a solution that meets my requirements. Those would be:
- Enums that provide code completion
- Enums that can be iterated over
- Not having to specify an element twice
- String based
The possibilities I've seen so far for enums in typescript are:
enum MyEnum {bla, blub}
: This fails at being string based, so I can't simply read from JSONs which are string based...type MyEnum = 'bla' | 'blub'
: Not iterable and no code completion- Do it yourself
class MyEnum { static get bla():string{return "bla"} ; static get blub():string{return "blub"}}
: Specifies elements twice
So here come the questions:
- There's no way to satisfy those requirements simultaneously? If no, will it be possible in the future?
- Why didn't they make
enums
string based? - Did someone experience similar problems and how did you solve them?