我有一个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会.default在thing_1和之间添加functionOnThing()?
没有名为defaulton的属性ThingStatic,并且default该.d.ts文件定义的底层JS对象上没有属性.
为什么TypeScript会添加属性以及如何阻止它?