-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Enum declared expression #4150
Enum declared expression #4150
Conversation
Hi @jbondc, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
I actually like the idea of this change, but the emit doesn't currently work for non-const enums - you get That said, that might be the way to go - if it's a const enum, you can do this, but otherwise it might be better to refrain. That way the rule for ambient enums doesn't have to change. Maybe others have a differing opinion on this. |
Can you explain why the error 'Ambient enum members can only have integer initializers.' was added? There's still obscure cases so I'm not sure what it's meant to enforce: foo.ts
tsc -d foo.ts
|
I think emitting a comment with the originating expression (option b) is far preferable here. |
So to clarify, with @RyanCavanaugh's suggestion, you'd get the following from your original example:
Though, you'd need to make sure you don't emit comments at all when doing so; you don't want something like enum hello {
a = 1
b = /*hello*/ a & a
} turning into declare enum hello {
a = 1
b = 1 /*/*hello*/ a & a*/
} |
It would be great to share the design notes on enums. I'm making efforts to get into the mindset but can't reach What I can understand is that the declaration file is tsc -d foo.ts
tsc -d --optimize foo.ts
In both cases |
When you write an enum and generate a declaration file:
The output is
You lose information about the intent/expression and is not useful if using definition files for documentation.
This patch preserves the original initializer expression when it resolves to a constant:
Note: This conflicts with the error:
Never really understood why that limitation exists, alternative could be to emit:
Use case within compiler (typescriptServices.d.ts):