[TS] Const enums in third party packages
See original GitHub issueI’m having problems using Typescript with the dependencies that use Const enums. I’m getting the folowing error: Type error: Ambient const enums are not allowed when the '--isolatedModules' flag is provided
.
I wanted to disable the flag but it seems CRA is forcing it. Is there a workaround around this?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
A Smaller Bundle with Const Enums in TypeScript
Enums allows us to define a set of named constants. By using enums we can keep our code DRY, easy to refactor, and...
Read more >Enums Features You Should Know in TypeScript
Numeric enums (not const ) will create forward ( name -> value ) and reverse ( value -> name ) mapping objects when...
Read more >exporting enum from typescript type definition file
Regarding enum , declaring them as const enum is a clean and simple approach. It's what is done for jquery for instance, see...
Read more >Handbook - Enums - TypeScript
Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined...
Read more >Idiomatic Alternatives to Enums in TypeScript - Medium
The const enum syntax is better aligned with the TS design goals of erasable ... that have better interoperability with third party APIs, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried turning off skipLibCheck? I’m using Monaco in an app as well (0.12 I think so a few months old)
It really depends on the build system, but I think in most situations setting
isolatedModules
tofalse
should just work.Some examples that I just tried:
start
script edits your tsconfig.json file to setisolatedModules
to true. I was able to get it working by ejecting, settingisolatedModules
to false in tsconfig.json, and removing theisolatedModules: true
line in the ForkTsCheckerWebpackPlugin constructor in config/webpack.config.dev.js and config/webpack.config.prod.js. As far as I know there isn’t a way to get it working without ejecting.ts-loader
, I’m pretty sure you can settranspileOnly: true
orhappyPackMode: true
and it will work just fine even whenisolatedModules
is false in your tsconfig.ts-node
, you can usets-node/register/transpile-only
just fine even whenisolatedModules
is false in the tsconfig.gulp-typescript
, I was able to get it to work by settingisolatedModules: false
in my tsconfig.json and by passing inisolatedModules: true
when callingcreateProject
. This switches it to use per-file compilation, and you don’t get anyisolatedModules
errors because it disables typechecking.In every one of these cases, setting
isolatedModules: false
is scary because it disables real safety checks that TypeScript would report. Setting it to false is a workaround to stop third-party libraries from breaking your build by including const enums, but it means that you need to be careful to not use TS features that need cross-file information to be transpiled (const enums, namespaces, re-exported types).