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

name is special #8132

Closed
richlim opened this issue Apr 17, 2016 · 15 comments
Closed

name is special #8132

richlim opened this issue Apr 17, 2016 · 15 comments
Labels
Bug A bug in TypeScript Docs The issue relates to how you learn TypeScript Fixed A PR has been merged for this issue

Comments

@richlim
Copy link

richlim commented Apr 17, 2016

TypeScript Version:

Version 1.9.0-dev.20160417

Code

// A self-contained demonstration of the problem follows...
let name: string = "hallo";

Expected behavior:
compile

Actual behavior:
error TS2451: Cannot redeclare block-scoped variable 'name'.

@DanielRosenwasser DanielRosenwasser added External Relates to another program, environment, or user action which we cannot control. By Design Deprecated - use "Working as Intended" or "Design Limitation" instead and removed External Relates to another program, environment, or user action which we cannot control. labels Apr 18, 2016
@DanielRosenwasser
Copy link
Member

The issue is that there's always a name when you're running in a browser environment:

https://developer.mozilla.org/en-US/docs/Web/API/Window/name

In TypeScript 2.0, you'll be able to exclude the definition using the lib flag if you're running in, say, Node.js.

@DanielRosenwasser
Copy link
Member

See also #8107.

@richlim
Copy link
Author

richlim commented Apr 19, 2016

Then maybe the TypeScript documentation should be changed?
In Basic Types:String:
let name: string = "bob";

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Docs The issue relates to how you learn TypeScript and removed By Design Deprecated - use "Working as Intended" or "Design Limitation" instead labels Apr 19, 2016
@RyanCavanaugh RyanCavanaugh reopened this Apr 19, 2016
@DanielRosenwasser
Copy link
Member

I already have fixed this at microsoft/TypeScript-Handbook#251, so we'll just need to republish the docs to the website.

@RyanCavanaugh RyanCavanaugh added the Fixed A PR has been merged for this issue label Apr 19, 2016
@ocombe
Copy link

ocombe commented Sep 12, 2016

@DanielRosenwasser is there anyway to get more context on where this "name" variable is defined ? I'm only getting ERROR in [default] C:\www\front-portal-v2\node_modules\typescript\lib\lib.d.ts:18448:14 Cannot redeclare block-scoped variable 'name'. but there are no details as to where it is in my code, and I cannot find it :(

@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2016

you should see another error for the other file, something like:

./node_modules/typescript/lib/lib.d.ts(18454,15): error TS2451: Cannot redeclare block-scoped variable 'name'.
./test/a.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'name'.

@ocombe
Copy link

ocombe commented Sep 12, 2016

no I'm not, that's the problem :(

@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2016

how are your running your compiler? what version of tsc are you using? can you share a repro?

@ocombe
Copy link

ocombe commented Sep 12, 2016

I'm using webpack 1.x with awesome-typescript-loader and typescript 2.0.2
I cannot share a repro as it is happening in a private work project and if I knew what was causing the problem in my code I'd fix it :D
I've downgraded to ts 2.0 for now

@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2016

so if you run tsc on the tsconfig directly not through awesome-typescript-loader, do you see the error?

@ocombe
Copy link

ocombe commented Sep 14, 2016

I retried with just tsc, no error, it builds the project just fine, I guess the problem lies within awesome-typescript-loader then :)

@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2016

I retried with just tsc, no error, it builds the project just fine,

what version of tsc were you using? this change was introduced in TS 2.0.

@ocombe
Copy link

ocombe commented Sep 14, 2016

I was using 2.0.0 before, and updated to 2.0.2, I updated awesome-typescript-loader from 2.2.1 to 2.2.4 at the same time

@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2016

that is not what i would expect. i would expect an error message for re-declaring a block-scoped variable. i would be interested to see a repro project if one is available.

@ocombe
Copy link

ocombe commented Sep 20, 2016

Ok, as it turns out the problem was with zone.js that was polluting the global namespace and replacing window.name (angular/zone.js#456), I just updated zone.js and the error disappeared !

@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
Bug A bug in TypeScript Docs The issue relates to how you learn TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants