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?
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.
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>).
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.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With