Don't emit const enum
s with reverse mapping (under preserveConstEnum
)
#37282
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
preserveConstEnums, const enum, enum
Suggestion
By default all
const enum
s are preserved from output. One of the key differences ofconst enum
s is disallowing to looking up the reversed value:This means that we can't access const enum's "reversed" member even if
preserveConstEnums
flag is enabled.JS code of
const enum
with enabledpreserveConstEnums
is pretty similar to justenum
s right now and contains string literals (even they couldn't be accessed from the code):My feature request is change output of
const enum
s whenpreserveConstEnums
is enabled and strip "reversed" values from it:Note: actually tsc already has similar behaviour if you specify string constant value for every const enum's member, but the values are strings, not numbers - it is kind of workaround if your const enum is used to declare string constants.
Use Cases
Reversed values for const enums are useless and cannot be accessed in the TS code, so why we should emit them? 🤔 I guess in this case the behaviour of
const enum
s from types and from execution (JS) purposes will be the same.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: