[api-extractor-model] Remove "const" keyword before enum to use with typescript isolatedModules #3074
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When a typescript project is using isolatedModules, referencing exported
const
enums is not allowed.Details
Setting
isolatedModules
totrue
is recommended for projects transpiled with babel or esbuild. Unliketsc
, these tools evaluate files independently. Setting theisolatedModules
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 thattsc
evaluatesconst enums
across modules and inlines the constants at compile. Noenum
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 usingisolatedModules
. 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 theReleaseTag
enum which is not usingconst
.