Skip to content

Make undefined valid as a type name #5387

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14885,7 +14885,9 @@ namespace ts {
getSymbolLinks(undefinedSymbol).type = undefinedType;
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
getSymbolLinks(unknownSymbol).type = unknownType;
globals[undefinedSymbol.name] = undefinedSymbol;
if (!globals[undefinedSymbol.name]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasProperty

globals[undefinedSymbol.name] = undefinedSymbol;
}
// Initialize special types
globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1);
globalObjectType = getGlobalType("Object");
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/undefinedAsName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [undefinedAsName.ts]
type undefined = string;
var x: undefined;

//// [undefinedAsName.js]
var x;
8 changes: 8 additions & 0 deletions tests/baselines/reference/undefinedAsName.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/undefinedAsName.ts ===
type undefined = string;
>undefined : Symbol(undefined, Decl(undefinedAsName.ts, 0, 0))

var x: undefined;
>x : Symbol(x, Decl(undefinedAsName.ts, 1, 3))
>undefined : Symbol(undefined, Decl(undefinedAsName.ts, 0, 0))

8 changes: 8 additions & 0 deletions tests/baselines/reference/undefinedAsName.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/undefinedAsName.ts ===
type undefined = string;
>undefined : string

var x: undefined;
>x : string
>undefined : string

2 changes: 2 additions & 0 deletions tests/cases/compiler/undefinedAsName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type undefined = string;
var x: undefined;