如何在 TypeScript 中声明“任何”模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31729668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to declare "any" module in TypeScript?
提问by user1338054
I need to migrate step by step some large project from js to typeScript.
我需要将一些大型项目从 js 逐步迁移到 typeScript。
I rewrite on of the files in ts and i want to specify that other files at this moment can contain any content.
我重写了 ts 中的文件,我想指定此时其他文件可以包含任何内容。
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?
我可以以某种快速的方式将外部模块声明为“任何”吗?
回答by Ryan Cavanaugh
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.
但是,这不会让你写foo.cls
。
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;
}