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.


Create a file in lib called errorInfoHandler.d.ts. There, write:

var noTypeInfoYet: any; // any var name here really
export = noTypeInfoYet;

Now the alert import will succeed and be of type any.


Either create your own definition file with following content:

declare module "lib/errorInfoHandler" {}

And reference this file where you want to use the import.

Or add the following line to the top of your file:

/// <amd-dependency path="lib/errorInfoHandler">

Note: I do not know if the latter still works, it's how I initially worked with missing AMD dependencies. Please also note that with this approach you will not have IntelliSense for that file.