-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access global
as a type
#14052
Comments
This is similar to #10050. Having a referenceable |
I would say this should be covered by #12902 |
@mhegazy Sorry, I read #12902 (comment) as a comment meaning it was really just a |
I think this is the feeling when we looked at this first. but I would expect users will have a similar request like yours. i would expect ppl wanting to do
I am fine lumping the two together, or keeping them separate. I would expect we need to do both if the proposal moves forward in the committee. |
We just ran in to this as well. We are handcoding typescript definitions for a legacy js library in the hope of pushing it to @types. We have multiple internal modules. One of the modules have a global variable X. And other have a variable X inside our common namespace Y. Now when the d.ts file of a third module want to refer the global X from inside our common namespace Y, there is no way right now. Any help on this? |
@nolakara the need for a way to fully qualify a name has been discussed previously in #983. we then concluded that there was not a pressing need for this with modules and aliasing support. The recommendation for this case is to alias the global variable outside of your namespace and use the alias instead, e.g.: import global_x = x;
namespace Y {
export class x { }
var local: x;
var global: global_x;
} |
One way I resolved this was to create a layer from global to register globals. In namespace "A" I register global "x". "y". "z" properties (i.e. Example: https://goo.gl/JreGBg
There is another way to access globals using
Using That assumes, of course, you are not trying to access a type (like an interface), and you will have to explicitly specify the expected type manually. |
Random update: We pretty much know we want to do this (and talked about it when we added |
This is now supported by using |
Since https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#augmenting-globalmodule-scope-from-modules it's been possible to augment the
global
from a module. However, in TypeScript definitions (such asdom.d.ts
ornode.d.ts
) we're left to create our own "globals". This results in two issue:window.
(browsers) orglobal.
(node)Instead of this, it'd be really nice to access TypeScript's
global
as a type. For instance, indom.d.ts
we could do:Or in
node.d.ts
:I couldn't see any previous issues, but it's partially related to things like #12902 - the difference though is that those issues seems to be tracking adding variables to the TypeScript global scope whereas this would be using the global scope as a type to define these variables themselves.
The text was updated successfully, but these errors were encountered: