coudy
coudy

Reputation: 13918

Does TypeScript have untyped external modules?

In other words, can I import an external JavaScript module without (initially) caring about its typing?

In pseudo-TypeScript:

declare module "foo": any;
import foo = module("foo");
foo.bar;
foo.baz();

Upvotes: 1

Views: 504

Answers (1)

Fenton
Fenton

Reputation: 250882

Yes you can - although not specifically as a module:

declare var foo : any;
foo.bar;
foo.baz();

As you aren't defining the module in any way, this should be sufficient.

Update

If you want to get a require statement generated, you would need a stronger definition inside of a foo.d.ts file. I usually recommend the require: any hack that you are trying to avoid.

Upvotes: 2

Related Questions