使用 TypeScript 2.7.2,在带有 @types/express 的 VSCode 版本 1.21 和随后的代码中,在某些情况下 VSCode 会抛出错误,说明
A namespace-style import cannot be called or constructed, and will cause a failure at runtime.
然而,在其他具有类似设置和类似 tsconfig.json
文件的机器上,代码就可以正常工作。这里发生了什么...
import { Bank } from './Bank';
import * as Express from 'express'; <== errors here..
let app: Express.Express;
this.app = Express(); <== and here
为什么会这样?
TIA,
约翰。
In my case I already had
"esModuleInterop": true
enabled intsconfig.json
. I needed to convert:import * as assert from "assert";
to:
import assert from "assert";