-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Error on types named "undefined" #57575
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
358ab6e
Add test
jakebailey 9fed7d1
New error
jakebailey 328be7b
Oops
jakebailey 6206462
Oops
jakebailey b376d0b
Error like other keywords, though undefined is not a keyword
jakebailey f8db707
Restore global
jakebailey ebd8d1c
new testing
jakebailey 3cfbd1a
reduce errors
jakebailey 115c0c5
baselines
jakebailey 0ecbb81
slightly better
jakebailey e82dde6
namespaces
jakebailey e777ac6
baseline
jakebailey 70973bb
baseline
jakebailey 886a41e
Revert namespace
jakebailey 7b80d7a
Eliminate builtinGlobals
jakebailey 49fa5c2
Small comment tweak to reflect final state
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
typeNamedUndefined1.ts(3,17): error TS2457: Type alias name cannot be 'undefined'. | ||
typeNamedUndefined1.ts(13,13): error TS2457: Type alias name cannot be 'undefined'. | ||
|
||
|
||
==== typeNamedUndefined1.ts (2 errors) ==== | ||
export namespace ns { | ||
const s = Symbol(); | ||
export type undefined = typeof s; | ||
~~~~~~~~~ | ||
!!! error TS2457: Type alias name cannot be 'undefined'. | ||
export function x(p: undefined): undefined { // global undefined | ||
return p; | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined) { // undefined from the namespace | ||
return p; | ||
} | ||
|
||
export type undefined = ""; | ||
~~~~~~~~~ | ||
!!! error TS2457: Type alias name cannot be 'undefined'. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined1.ts] //// | ||
|
||
//// [typeNamedUndefined1.ts] | ||
export namespace ns { | ||
const s = Symbol(); | ||
export type undefined = typeof s; | ||
export function x(p: undefined): undefined { // global undefined | ||
return p; | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined) { // undefined from the namespace | ||
return p; | ||
} | ||
|
||
export type undefined = ""; | ||
|
||
|
||
//// [typeNamedUndefined1.js] | ||
export var ns; | ||
(function (ns) { | ||
const s = Symbol(); | ||
function x(p) { | ||
return p; | ||
} | ||
ns.x = x; | ||
})(ns || (ns = {})); | ||
export function x(p) { | ||
return p; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined1.ts] //// | ||
|
||
=== typeNamedUndefined1.ts === | ||
export namespace ns { | ||
>ns : Symbol(ns, Decl(typeNamedUndefined1.ts, 0, 0)) | ||
|
||
const s = Symbol(); | ||
>s : Symbol(s, Decl(typeNamedUndefined1.ts, 1, 9)) | ||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) | ||
|
||
export type undefined = typeof s; | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined1.ts, 1, 23)) | ||
>s : Symbol(s, Decl(typeNamedUndefined1.ts, 1, 9)) | ||
|
||
export function x(p: undefined): undefined { // global undefined | ||
>x : Symbol(x, Decl(typeNamedUndefined1.ts, 2, 37)) | ||
>p : Symbol(p, Decl(typeNamedUndefined1.ts, 3, 22)) | ||
|
||
return p; | ||
>p : Symbol(p, Decl(typeNamedUndefined1.ts, 3, 22)) | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined) { // undefined from the namespace | ||
>x : Symbol(x, Decl(typeNamedUndefined1.ts, 6, 1)) | ||
>p : Symbol(p, Decl(typeNamedUndefined1.ts, 8, 18)) | ||
>ns : Symbol(ns, Decl(typeNamedUndefined1.ts, 0, 0)) | ||
>undefined : Symbol(ns.undefined, Decl(typeNamedUndefined1.ts, 1, 23)) | ||
|
||
return p; | ||
>p : Symbol(p, Decl(typeNamedUndefined1.ts, 8, 18)) | ||
} | ||
|
||
export type undefined = ""; | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined1.ts, 10, 1)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined1.ts] //// | ||
|
||
=== typeNamedUndefined1.ts === | ||
export namespace ns { | ||
>ns : typeof ns | ||
|
||
const s = Symbol(); | ||
>s : unique symbol | ||
>Symbol() : unique symbol | ||
>Symbol : SymbolConstructor | ||
|
||
export type undefined = typeof s; | ||
>undefined : unique symbol | ||
>s : unique symbol | ||
|
||
export function x(p: undefined): undefined { // global undefined | ||
>x : (p: undefined) => undefined | ||
>p : undefined | ||
|
||
return p; | ||
>p : undefined | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined) { // undefined from the namespace | ||
>x : (p: ns.undefined) => symbol | ||
>p : unique symbol | ||
>ns : any | ||
|
||
return p; | ||
>p : unique symbol | ||
} | ||
|
||
export type undefined = ""; | ||
>undefined : "" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
typeNamedUndefined2.ts(4,21): error TS2457: Type alias name cannot be 'undefined'. | ||
typeNamedUndefined2.ts(17,17): error TS2457: Type alias name cannot be 'undefined'. | ||
|
||
|
||
==== typeNamedUndefined2.ts (2 errors) ==== | ||
export namespace ns { | ||
export namespace undefined { | ||
export const s = Symbol(); | ||
export type undefined = typeof s; | ||
~~~~~~~~~ | ||
!!! error TS2457: Type alias name cannot be 'undefined'. | ||
}; | ||
export function x(p: undefined): undefined { | ||
return p; | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined.undefined) { | ||
return p; | ||
} | ||
|
||
export namespace undefined { | ||
export const s = Symbol(); | ||
export type undefined = typeof s; | ||
~~~~~~~~~ | ||
!!! error TS2457: Type alias name cannot be 'undefined'. | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined2.ts] //// | ||
|
||
//// [typeNamedUndefined2.ts] | ||
export namespace ns { | ||
export namespace undefined { | ||
export const s = Symbol(); | ||
export type undefined = typeof s; | ||
}; | ||
export function x(p: undefined): undefined { | ||
return p; | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined.undefined) { | ||
return p; | ||
} | ||
|
||
export namespace undefined { | ||
export const s = Symbol(); | ||
export type undefined = typeof s; | ||
}; | ||
|
||
|
||
//// [typeNamedUndefined2.js] | ||
export var ns; | ||
(function (ns) { | ||
let undefined; | ||
(function (undefined) { | ||
undefined.s = Symbol(); | ||
})(undefined = ns.undefined || (ns.undefined = {})); | ||
; | ||
function x(p) { | ||
return p; | ||
} | ||
ns.x = x; | ||
})(ns || (ns = {})); | ||
export function x(p) { | ||
return p; | ||
} | ||
export var undefined; | ||
(function (undefined) { | ||
undefined.s = Symbol(); | ||
})(undefined || (undefined = {})); | ||
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined2.ts] //// | ||
|
||
=== typeNamedUndefined2.ts === | ||
export namespace ns { | ||
>ns : Symbol(ns, Decl(typeNamedUndefined2.ts, 0, 0)) | ||
|
||
export namespace undefined { | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined2.ts, 0, 21)) | ||
|
||
export const s = Symbol(); | ||
>s : Symbol(s, Decl(typeNamedUndefined2.ts, 2, 20)) | ||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) | ||
|
||
export type undefined = typeof s; | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined2.ts, 2, 34)) | ||
>s : Symbol(s, Decl(typeNamedUndefined2.ts, 2, 20)) | ||
|
||
}; | ||
export function x(p: undefined): undefined { | ||
>x : Symbol(x, Decl(typeNamedUndefined2.ts, 4, 6)) | ||
>p : Symbol(p, Decl(typeNamedUndefined2.ts, 5, 22)) | ||
|
||
return p; | ||
>p : Symbol(p, Decl(typeNamedUndefined2.ts, 5, 22)) | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined.undefined) { | ||
>x : Symbol(x, Decl(typeNamedUndefined2.ts, 8, 1)) | ||
>p : Symbol(p, Decl(typeNamedUndefined2.ts, 10, 18)) | ||
>ns : Symbol(ns, Decl(typeNamedUndefined2.ts, 0, 0)) | ||
>undefined : Symbol(ns.undefined, Decl(typeNamedUndefined2.ts, 0, 21)) | ||
>undefined : Symbol(ns.undefined.undefined, Decl(typeNamedUndefined2.ts, 2, 34)) | ||
|
||
return p; | ||
>p : Symbol(p, Decl(typeNamedUndefined2.ts, 10, 18)) | ||
} | ||
|
||
export namespace undefined { | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined2.ts, 12, 1)) | ||
|
||
export const s = Symbol(); | ||
>s : Symbol(s, Decl(typeNamedUndefined2.ts, 15, 16)) | ||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) | ||
|
||
export type undefined = typeof s; | ||
>undefined : Symbol(undefined, Decl(typeNamedUndefined2.ts, 15, 30)) | ||
>s : Symbol(s, Decl(typeNamedUndefined2.ts, 15, 16)) | ||
|
||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//// [tests/cases/compiler/typeNamedUndefined2.ts] //// | ||
|
||
=== typeNamedUndefined2.ts === | ||
export namespace ns { | ||
>ns : typeof ns | ||
|
||
export namespace undefined { | ||
>undefined : typeof undefined | ||
|
||
export const s = Symbol(); | ||
>s : unique symbol | ||
>Symbol() : unique symbol | ||
>Symbol : SymbolConstructor | ||
|
||
export type undefined = typeof s; | ||
>undefined : unique symbol | ||
>s : unique symbol | ||
|
||
}; | ||
export function x(p: undefined): undefined { | ||
>x : (p: undefined) => undefined | ||
>p : undefined | ||
|
||
return p; | ||
>p : undefined | ||
} | ||
} | ||
|
||
export function x(p: ns.undefined.undefined) { | ||
>x : (p: ns.undefined.undefined) => symbol | ||
>p : unique symbol | ||
>ns : any | ||
>undefined : any | ||
|
||
return p; | ||
>p : unique symbol | ||
} | ||
|
||
export namespace undefined { | ||
>undefined : typeof undefined | ||
|
||
export const s = Symbol(); | ||
>s : unique symbol | ||
>Symbol() : unique symbol | ||
>Symbol : SymbolConstructor | ||
|
||
export type undefined = typeof s; | ||
>undefined : unique symbol | ||
>s : unique symbol | ||
|
||
}; | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/undefinedTypeAssignment1.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to eliminate builtinGlobals while here; its only use is to complain about undefined, but now we're going to complain even less and the new code had to exclude type declarations anyway.