How to import a js library without definition file in typescript file

A combination of the 2 answers given here worked for me.

//errorInfoHandler.d.ts
declare module "lib/errorInfoHandler" {
   var noTypeInfoYet: any; // any var name here really
   export = noTypeInfoYet;
}

I’m still new to TypeScript but it looks as if this is just a way to tell TypeScript to leave off by exporting a dummy variable with no type information on it.

EDIT

It has been noted in the comments for this answer that you can achieve the same result by simply declaring:

//errorInfoHandler.d.ts
declare module "*";

See the github comment here.

Leave a Comment