Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare "any" module in TypeScript?

Tags:

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?

like image 666
user1338054 Avatar asked Jul 30 '15 16:07

user1338054


People also ask

Which keyword is used to declare a module in TypeScript?

A module can be created using the keyword export and a module can be used in another module using the keyword import . In TypeScript, files containing a top-level export or import are considered modules. For example, we can make the above files as modules as below. console.

How do I use TypeScript modules?

External modules in TypeScript exists to specify and load dependencies between multiple external js files. If there is only one js file used, then external modules are not relevant. Traditionally dependency management between JavaScript files was done using browser script tags (<script></script>).

How do I import a custom module in TypeScript?

Approach: Before importing any module we need to export it from another file. We can create a module by using the export keyword and can use it in other modules by using the import keyword. We can export both class-based modules and function-based modules. as shown below.


1 Answers

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; } 
like image 146
Ryan Cavanaugh Avatar answered Oct 19 '22 18:10

Ryan Cavanaugh