question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TS] Const enums in third party packages

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ianschmitzcommented, Nov 9, 2018

Have you tried turning off skipLibCheck? I’m using Monaco in an app as well (0.12 I think so a few months old)

1reaction
alangpiercecommented, Dec 2, 2018

@alangpierce could you describe how you set it up?

It really depends on the build system, but I think in most situations setting isolatedModules to false should just work.

Some examples that I just tried:

  • Create React App is the most difficult since the start script edits your tsconfig.json file to set isolatedModules to true. I was able to get it working by ejecting, setting isolatedModules to false in tsconfig.json, and removing the isolatedModules: 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.
  • With ts-loader, I’m pretty sure you can set transpileOnly: true or happyPackMode: true and it will work just fine even when isolatedModules is false in your tsconfig.
  • With ts-node, you can use ts-node/register/transpile-only just fine even when isolatedModules is false in the tsconfig.
  • With gulp-typescript, I was able to get it to work by setting isolatedModules: false in my tsconfig.json and by passing in isolatedModules: true when calling createProject. This switches it to use per-file compilation, and you don’t get any isolatedModules 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found