Looking into the official guide on module loading in Typescript, I came across a section called "Ambient Modules" which discusses loading modules not written in Typescript. Intrigued, I decided to try implementing this method for a simple learning project.
The goal is to utilize Typescript to load the MyThing.js library below:
// myThings.js
function getMyThing (){
return "This is my thing";
}
function getMyObject() {
return {
a: 1,
b: "my object"
}
}
Here is my myThing.d.ts file:
// myThing.d.ts
declare module myThing {
interface MyObject {
a: number;
b: string;
}
export function getMyThing():string;
export function getMyObject():MyObject;
}
Now here's the app.ts that is meant to use the myThing library:
// app.ts
import {getMyThing} from "./myThing.d";
All files - myThing.js, myThing.d.ts, and app.ts - are stored in the same folder. But unfortunately, things aren't going smoothly. Upon compiling app.ts, I encountered the following error:
myThing.d.ts' is not a module. (2306)
So here's my plea: How can I successfully import a non-Typescript module? Do I need to incorporate declare files? If possible, could you please provide some code snippets using the provided demo files?
I've already spent time sifting through the official documentation, but I'm still stumped. Help would be greatly appreciated!