Having a global definition within an external library file named thing.d.ts
:
declare var thing: ThingStatic;
export default thing;
Importing the npm module in TypeScript:
import thing from 'thing';
...
thing.functionOnThing();
After transpiling the TypeScript (with ES6 target), it results in:
const thing_1 = require("thing");
...
thing_1.default.functionOnThing();
Leading to the error message:
Cannot read property 'functionOnThing' of undefined
The confusion lies in why TypeScript is inserting .default
between thing_1
and functionOnThing()
.
It's important to note that there is no default
property defined on ThingStatic
, nor on the underlying JS object specified in the .d.ts
file.
Understanding why TypeScript includes this property and how to prevent it is crucial. Can anyone provide insight on fixing this issue?