Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - isolatedModules and JSON import

We are using a Babel to compile our TypeScript files and we want to use isolatedModules: true in our tsconfig.json as it is a recommended way. It, for example, throws an error when you try to re-export an interface. This is a necessary feature as Babel TypeScript compiler doesn't allow that too.

However, we need to import a JSON file in our TS file. The issue is that tsc will throws the following error:

Cannot compile namespaces when the '--isolatedModules' flag is provided.

Any idea how to import a JSON and keep type-checker happy?

like image 605
Deftomat Avatar asked Aug 30 '18 18:08

Deftomat


1 Answers

This was a TypeScript bug and the fix was just merged to master: https://github.com/Microsoft/TypeScript/pull/28207

It should be available on 3.1.4+.

like image 80
Bruno Lemos Avatar answered Oct 24 '22 10:10

Bruno Lemos