从 TypeScript 声明全局命名空间变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18171967/
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
declare global namespace variable from TypeScript
提问by Olivier Refalo
How to explicitly declare a variable in the global namespace from typescript?
如何在打字稿的全局命名空间中显式声明变量?
I need the compiler to generate the following javascript code:
我需要编译器生成以下 javascript 代码:
MyExtension = someFunction()
unfortunately, I can only have it generate
不幸的是,我只能让它生成
var MyExtension = someFunction()
This comes to an issue with the latest version (still in rc) of meteor packages. Meteor introduced a way to scope namespaces in packages - the issue is, the variable needs to be defined in the global namespace (which meteor reroutes to its own Package object).
这涉及到最新版本(仍在 rc 中)的流星包的问题。Meteor 引入了一种在包中定义命名空间范围的方法——问题是,变量需要在全局命名空间中定义(流星重新路由到它自己的包对象)。
There is a video about it at https://www.eventedmind.com/posts/meteor-linker-package-namespacing.
在https://www.eventedmind.com/posts/meteor-linker-package-namespacing 上有一个关于它的视频。
Is there some kind of globalkeyword available or in the plans?
是否有某种global关键字可用或在计划中?
回答by basarat
Use the declarekeyword. These are known as ambient declarations.
使用declare关键字。这些被称为环境声明。
declare var MyExtentention:any;

