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

Variable of name, "name", is not validated #5694

Closed
xealot opened this issue Nov 16, 2015 · 3 comments
Closed

Variable of name, "name", is not validated #5694

xealot opened this issue Nov 16, 2015 · 3 comments

Comments

@xealot
Copy link

xealot commented Nov 16, 2015

When a variable is named "name" (let name;) it is not checked for validity.

For example:

let s = {};
console.log(s[t]);

The tsc command fails on this code since t obviously doesn't exist. However, changing nothing else but the variable used in the object's index...

let s = {};
console.log(s[name]);

... tsc doesn't complain at all about this. To me this seems like a bug. Why are variables named name special?

Apologies if I missed an already open issue but due to the nature of the terms used to describe this issue it's kinda hard to search on.

@RyanCavanaugh
Copy link
Member

name is the global that you could also access via window.name (https://developer.mozilla.org/en-US/docs/Web/API/Window/name)

@RyanCavanaugh
Copy link
Member

See also #1351 (comment) for a good explanation of why it would be a bad idea to remove the global name declaration, as one might be tempted to do.

@xealot
Copy link
Author

xealot commented Nov 16, 2015

I had a sneaking suspicion that it was falling back to a higher scope. Silly javascript. I tried the last suggestion in the thread you mentioned but it seemed to work fine. I'll comment there. Thank you once again @RyanCavanaugh!

@xealot xealot closed this as completed Nov 16, 2015
@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants