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

Compiler option to force explicit access for global properties #524

Closed
andrewvarga opened this issue Aug 26, 2014 · 4 comments
Closed

Compiler option to force explicit access for global properties #524

andrewvarga opened this issue Aug 26, 2014 · 4 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@andrewvarga
Copy link

I've hurt myself multiple times with code like this:

var x = length / 2;

the problem is that I forgot to declare the "length" variable but because one exists as "window.length" this compiles without a problem.
A good help would be a stricter compiler option which would only allow accessing global properties like this:

window.length
@RyanCavanaugh
Copy link
Member

This is already reasonably possible -- just delete all the globals you don't like from lib.d.ts (look around line 9800). Once we have #494 implemented, it will be straightforward to have a lib_noglobals.d.ts file that gives you the desired behavior.

@andrewvarga
Copy link
Author

Ok, but if I delete such globals how will I see them when I do want to access them via "window.length" ? Won't that remove them completely ?

@RyanCavanaugh
Copy link
Member

No. window.length is declared on line 3523 as a member of the Window interface.

@andrewvarga
Copy link
Author

Got it. Indeed that solves it then, thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants