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

The global 'name' variable should be declared as a const of type 'never' #9850

Closed
DanielRosenwasser opened this issue Jul 21, 2016 · 3 comments
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

As discussed, the name global variable causes certain problems. We decided that it should be changed to a const with the type never.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Breaking Change Would introduce errors in existing code Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jul 21, 2016
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.0.1 milestone Aug 1, 2016
@zhengbli zhengbli reopened this Aug 19, 2016
@zhengbli zhengbli added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo labels Aug 22, 2016
@anta0
Copy link

anta0 commented Nov 28, 2016

I think the type of 'name' variable should be 'void' instead of 'never' if we want to prevent misuse.
For example, function f(x: string) { } f(name); this code compiles in the current version but it shouldn't.
The original example from #1351 console.log(name); can't be prevented as long as there is a declaration, though.

@connorjclark
Copy link
Contributor

Accidentally used name (with no previous declaration) in JSX - compiled but failed at runtime.

{name}

If it were declare const name: void instead of declare const name: never, the above would properly fail to compile.

Is there a reason this must be never?

@RyanCavanaugh
Copy link
Member

@hoten #15424 is the long thread to read why never is the best available type for name

@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants