-
Notifications
You must be signed in to change notification settings - Fork 607
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
[api-extractor] Remove "const" keyword before enum to use with typescript isolatedModules #4541
Conversation
@IIIMADDINIII please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should be fine in this package.
Summary
When a typescript project is using isolatedModules, referencing exported const enums is not allowed.
Details
Setting isolatedModules to true is recommended for projects transpiled with babel or esbuild. Unlike tsc, these tools evaluate files independently. Setting the isolatedModules flag e.g. forces developers to indicate whether they are exporting a type or value, since transpilers evaluating modules independently cannot infer this information.
However, the flag also alerts when a const enum is used. It seems that tsc evaluates const enums across modules and inlines the constants at compile. No enum object is created, which is problematic of independent transpilation.
I found this article helpful for understanding the effect of specifying const.
By removing the const keyword, the enums can safely be used in projects using isolatedModules. This change is similar to #3060 and #3074.
How it was tested
Build passes.