Skip to content
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

Allow augmenting the global scope with new names #7161

Closed
yortus opened this issue Feb 20, 2016 · 3 comments
Closed

Allow augmenting the global scope with new names #7161

yortus opened this issue Feb 20, 2016 · 3 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@yortus
Copy link
Contributor

yortus commented Feb 20, 2016

It would be great if TypeScript could model situations where new names are added to the global scope.

This was described by a team member as a desirable feature that could definitely be enabled in #7015 (comment). However that issue is closed, and I can't find any other open issue tracking the suggestion, so I opened this one.

A basic example:

// File: foo.ts

// Augment the global scope to add foo
declare global {
    var foo: Function;  // ERROR: Cannot introduce new top level names
}

// Implement foo
var fooImpl = () => {/***/};
foo = fooImpl;  // OK - compiler 'sees' global foo here
export default fooImpl;

// Reference foo
foo();          // OK - compiler 'sees' global foo here

Currently this produces a compiler error as shown above. Interestingly, the global foo is recognised at the two other sites where it is referenced in the example. So it appears this would already work just if the error message was suppressed.

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 20, 2016
@yortus
Copy link
Contributor Author

yortus commented Apr 16, 2016

Fixed by #8104?

@basarat
Copy link
Contributor

basarat commented Apr 16, 2016

Fixed by #8104?

@yortus indeed. Just tested and it works out of the box 🌹

image

@yortus
Copy link
Contributor Author

yortus commented Apr 16, 2016

Sweet! Thanks for checking @basarat

@yortus yortus closed this as completed Apr 16, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed In Discussion Not yet reached consensus labels Apr 17, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Apr 17, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants