【发布时间】:2017-04-30 02:31:39
【问题描述】:
我有一个外部库 thing.d.ts 文件,里面有一个全局定义:
declare var thing: ThingStatic;
export default thing;
我在我的 TypeScript 中引用了 npm 模块:
import thing from 'thing';
...
thing.functionOnThing();
当我转译 TS(针对 ES6)时,它看起来像这样:
const thing_1 = require("thing");
...
thing_1.default.functionOnThing();
这会引发错误:
无法读取未定义的属性“functionOnThing”
为什么 TypeScript 在thing_1 和functionOnThing() 之间添加.default?
ThingStatic 上没有名为 default 的属性,.d.ts 文件定义的底层 JS 对象上也没有 default 属性。
TypeScript 为什么要添加该属性,我该如何停止它?
【问题讨论】:
标签: javascript typescript ecmascript-6 typescript-typings