-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Component commits: 0edae12 Reduce void | undefined only in conjunction with subtype reduction 6b487a6 Accept new baselines e7b6601 Add regression test Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
- Loading branch information
1 parent
16f2556
commit 57ba6dd
Showing
16 changed files
with
129 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 @@ | ||
//// [voidUndefinedReduction.ts] | ||
// Repro from #42786 | ||
|
||
function isDefined<T>(value: T | undefined | null | void): value is T { | ||
return value !== undefined && value !== null; | ||
} | ||
|
||
declare const foo: string | undefined; | ||
|
||
if (isDefined(foo)) { | ||
console.log(foo.toUpperCase()); | ||
} | ||
|
||
|
||
//// [voidUndefinedReduction.js] | ||
"use strict"; | ||
// Repro from #42786 | ||
function isDefined(value) { | ||
return value !== undefined && value !== null; | ||
} | ||
if (isDefined(foo)) { | ||
console.log(foo.toUpperCase()); | ||
} |
This file contains 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,33 @@ | ||
=== tests/cases/compiler/voidUndefinedReduction.ts === | ||
// Repro from #42786 | ||
|
||
function isDefined<T>(value: T | undefined | null | void): value is T { | ||
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0)) | ||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) | ||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) | ||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) | ||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) | ||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) | ||
|
||
return value !== undefined && value !== null; | ||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) | ||
>undefined : Symbol(undefined) | ||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) | ||
} | ||
|
||
declare const foo: string | undefined; | ||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) | ||
|
||
if (isDefined(foo)) { | ||
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0)) | ||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) | ||
|
||
console.log(foo.toUpperCase()); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>foo.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
|
This file contains 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,37 @@ | ||
=== tests/cases/compiler/voidUndefinedReduction.ts === | ||
// Repro from #42786 | ||
|
||
function isDefined<T>(value: T | undefined | null | void): value is T { | ||
>isDefined : <T>(value: T | undefined | null | void) => value is T | ||
>value : void | T | null | undefined | ||
>null : null | ||
|
||
return value !== undefined && value !== null; | ||
>value !== undefined && value !== null : boolean | ||
>value !== undefined : boolean | ||
>value : void | T | null | undefined | ||
>undefined : undefined | ||
>value !== null : boolean | ||
>value : T | null | ||
>null : null | ||
} | ||
|
||
declare const foo: string | undefined; | ||
>foo : string | undefined | ||
|
||
if (isDefined(foo)) { | ||
>isDefined(foo) : boolean | ||
>isDefined : <T>(value: void | T | null | undefined) => value is T | ||
>foo : string | undefined | ||
|
||
console.log(foo.toUpperCase()); | ||
>console.log(foo.toUpperCase()) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>foo.toUpperCase() : string | ||
>foo.toUpperCase : () => string | ||
>foo : string | ||
>toUpperCase : () => string | ||
} | ||
|
This file contains 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,13 @@ | ||
// @strict: true | ||
|
||
// Repro from #42786 | ||
|
||
function isDefined<T>(value: T | undefined | null | void): value is T { | ||
return value !== undefined && value !== null; | ||
} | ||
|
||
declare const foo: string | undefined; | ||
|
||
if (isDefined(foo)) { | ||
console.log(foo.toUpperCase()); | ||
} |