Is there a way to use --esModuleInterop in tsconfig as opposed to it being a flag?

前端 未结 2 858
执念已碎
执念已碎 2020-12-09 07:46

Typescript v 2.7 released really neat flag called --esModuleInterop https://www.typescriptlang.org/docs/handbook/compiler-options.html, I am trying to figure ou

2条回答
  •  情书的邮戳
    2020-12-09 08:05

    Yes, do "esModuleInterop": true in your tsconfig.json. For every flag option that can be passed to the CLI, the same can usually be done this way in the config file. Doing tsc --init on the command line generates a tsconfig full of comments explaining all of the available options.


    EDIT: I've learned that the behavior of esModuleInterop is dependent on what is set to module.

    If you have "module": "commonjs", you only need to enable "esModuleInterop": true.

    If you have "module": "es2015" or "module": "esnext", you also have to enable "allowSyntheticDefaultImports": true in order to import CommonJS modules (like React) as a default.

提交回复
热议问题