相关疑难解决方法(0)

为什么TypeScript将.default添加到全局定义的导入?

我有一个thing.d.ts带有全局定义的外部库文件:

declare var thing: ThingStatic;
export default thing;
Run Code Online (Sandbox Code Playgroud)

我在TypeScript中引用了npm模块:

import thing from 'thing';
...
thing.functionOnThing();
Run Code Online (Sandbox Code Playgroud)

当我转换TS(针对ES6)时,它看起来像这样:

const thing_1 = require("thing");
...
thing_1.default.functionOnThing();
Run Code Online (Sandbox Code Playgroud)

然后抛出一个错误:

无法读取未定义的属性'functionOnThing'

为什么TypeScript会.defaultthing_1和之间添加functionOnThing()

没有名为defaulton的属性ThingStatic,并且default.d.ts文件定义的底层JS对象上没有属性.

为什么TypeScript会添加属性以及如何阻止它?

javascript typescript ecmascript-6 typescript-typings

7
推荐指数
2
解决办法
1351
查看次数