Here is the official document covering the module loading in Typescript. A section titled "Ambient Modules" is talking about loading module that is not written in Typescript. I am trying to do simple learning project to use the method explained in the official document to load a module.
I am trying to use Typescript to load this following MyThing.js library.
// 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;
}
Here is the app.ts that use the myThing library.
// app.ts
import {getMyThing} from "./myThing.d";
myThing.js, myThing.d.ts, and app.ts are in the same folder. Oh boy, nothing is right. When I compile app.ts, got the following error:
myThing.d.ts' is not a module. (2306)
My question is how do I import a module that is not written in Typescript? Do I have to use declare file? Please provide sample code using the demo files above.
I've already read the official document, but still couldn't get it right.