user1338054
user1338054

Reputation: 869

How to declare "any" module in TypeScript?

I need to migrate step by step some large project from js to typeScript.

I rewrite on of the files in ts and i want to specify that other files at this moment can contain any content.

For example something like that:

declare module jsModule:any;
var obj:jsModule.cls = new jsModule.cls()

But it does not work in this moment. I need to specify each exported class/function/variable in module declaration.

Can i declare external module as "any" in some fast way?

Upvotes: 26

Views: 27022

Answers (2)

trusktr
trusktr

Reputation: 45494

declare module 'foo';

then

import {foo, bar, blah} from 'foo' // ok, no error (everything type any)

Upvotes: 1

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221212

For an external module with no exposed types and any values:

declare module 'Foo' {
  var x: any;
  export = x;
}

This won't let you write foo.cls, though.

If you're stubbing out individual classes, you can write:

declare module 'Foo' {
    // The type side
    export type cls = any;
    // The value side
    export var cls: any;
}

Upvotes: 31

Related Questions