Skip to content

[api-extractor-model] Remove "const" keyword before enum to use with typescript isolatedModules #3074

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

Merged
merged 4 commits into from
Dec 8, 2021

Conversation

samisayegh
Copy link
Contributor

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 this recent PR.

How it was tested

I used npm link and no longer saw the error. Note also that I did not face the error with the ReleaseTag enum which is not using const.

@ghost
Copy link

ghost commented Dec 6, 2021

CLA assistant check
All CLA requirements met.

@samisayegh
Copy link
Contributor Author

samisayegh commented Dec 6, 2021

When running rush change on the forked repo, I see the following error:

rush_change_error

Not sure what to do hmm

Edit: I ran the command in the original repo and copied the generated dir into the forked repo.

@samisayegh samisayegh changed the title [api-extractor] Remove "const" keyword before enum to allow use with typescript isolatedModules [api-extractor] Remove "const" keyword before enum to use with typescript isolatedModules Dec 7, 2021
@samisayegh samisayegh changed the title [api-extractor] Remove "const" keyword before enum to use with typescript isolatedModules [api-extractor-model] Remove "const" keyword before enum to use with typescript isolatedModules Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants