declare global namespace variable from TypeScript

痞子三分冷 提交于 2020-01-13 07:39:21

问题


How to explicitly declare a variable in the global namespace from typescript?

I need the compiler to generate the following javascript code:

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).

There is a video about it at https://www.eventedmind.com/posts/meteor-linker-package-namespacing.

Is there some kind of global keyword available or in the plans?


回答1:


Use the declare keyword. These are known as ambient declarations.

declare var MyExtentention:any;


来源:https://stackoverflow.com/questions/18171967/declare-global-namespace-variable-from-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!