I am attempting to port a Javascript project to Typescript. I have a dependency named like: @myscope/utils
A file from this is imported into the ts file
I managed to solve this myself. I referred to the information on writing declaration files
The key to get the module to be resolved is to declare a module with a name of the full path of the package. I created a index.d.ts
file for the module, that I added to my files
section of tsconfig.json
.
The file contained the following declaration:
declare namespace date {
function now(): number;
}
declare module "@myscope/utils/date" {
export = date;
}
Though not necessary, I structured my imports like typings does. I may simplify later after I've ported the rest of the application.
I created the following files:
mytypings/index.d.ts
mytypings/modules/@myscope/utils/index.d.ts
Note there is no date part of the utils path.
mytypings/index.d.ts
contains a reference path to mytypings/modules/@myscope/utils/index.d.ts
and then was added to section of tsconfig.json
.
My plan is to add other libraries in the same way.