Do I ever need explicit allowSyntheticDefaultImports if esModuleInterop is true configuring TypeScript transpilation?

后端 未结 2 557
天命终不由人
天命终不由人 2020-12-30 20:35

I need confirmation on the following theory. According to TS docs, there are two options that can be set in tsconfig.json.

  1. --allowSynth

2条回答
  •  梦毁少年i
    2020-12-30 21:23

    If you mean can you leave allowSyntheticDefaultImports undefined and define only esModuleInterop, the answer should be YES moving forward, but there has been an issue with this. PR #26866 seems to be a fix, only merged September 17, so it there may be some risk in the short term.

    As why both exist, I believe these were both a part of addressing compatibility issues with imports of Babel-transpiled modules, the original PR added the allowSyntheticDefaultImports option to certain compile-time messages, but in practice didn't address the runtime behavior of the imports. So --esModuleInterop was added later. See TypeScript-Handbook/#816 for discussion of how to update the docs...

提交回复
热议问题