问题
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