My issue revolves around an external JS library that contains a global parameter:
function Thing() { ... }
...
var thing = new Thing();
I have a TypeScript definition file named thing.d.ts
with the following content:
declare var thing: ThingStatic;
export default thing;
export interface ThingStatic {
functionOnThing(): ThingFoo;
}
export interface ThingFoo {
... and so on
To use this library in my own TS files, I import it like this:
import thing from 'thing';
import {ThingFoo} from 'thing';
...
const x:ThingFoo = thing.functionOnThing();
The problem arises when this code is transpiled to:
const thing_1 = require("thing");
...
thing_1.default.functionOnThing();
This leads to an error. After seeking help in another question, the suggestion was to try:
import * as thing from 'thing';
However, this does not resolve the issue - it introduces thing.default
in TS, but once transpiled to JS, it remains undefined.
It appears that there might be an issue with thing.d.ts
- there should be a way to define a typed global parameter for proper import.
How should thing.d.ts
be written to accurately represent the JS without transpiling unnecessary properties like default
which are not actually present?