microsoft/TypeScript

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

DanielRosenwasser opened this issue · 3 comments

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

anta0 commented

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.

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?

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