-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String Based Enum - Reverse Mapping Problem #21935
Comments
String enums has no reverse mapping. Is by design. See last part of entry post of #15486. |
Thanks for your information |
@RyanCavanaugh Hi! Could you please explain, why the TS team insists on string enums not having reverse mapping functionality? I have found lots of discussions about it but did not find the rationale behind the decision. Thanks a lot! Cheers, Marcel |
If we provided the reverse map automatically (which, by the way, is not necessarily non-ambiguous!), then you'd have no way to distinguish keys from values unless there was a completely separate object created at runtime. It is trivial to write a function that constructs the reverse map if you want it; our goal is to emit as little code as possible so it makes sense to just emit the data you need (to keep code size down) and let you construct the reverse map on an as-needed basis. |
@RyanCavanaugh That makes sense. Thanks a lot for the explanation! :-) |
My TypeScript Version is 2.7.1
The output are as follows
vx is INR
enum name is undefined
In Line 9, the reverse mapping is not working for string based enum.
Thanks
Kannan Wisen
The text was updated successfully, but these errors were encountered: