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?
To declare a global variable in TypeScript, create a . d. ts file and use declare global{} to extend the global object with typings for the necessary properties or methods.
The namespace is used for logical grouping of functionalities. A namespace can include interfaces, classes, functions and variables to support a single or a group of related functionalities. A namespace can be created using the namespace keyword followed by the namespace name.
Global variables are defined outside a function, usually on top of the program. Global variables hold their values throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program.
Use the declare
keyword. These are known as ambient declarations.
declare var MyExtentention: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