forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use bidirectional comparability (aka comparability) in narrowing
- Loading branch information
1 parent
19defbf
commit 46ce0b2
Showing
5 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [50527.ts] | ||
type S = | ||
| { type: 'string', value: string } | ||
| { type: 'number', value: number } | ||
| { type: 'unknown', value: unknown } | ||
| { value: undefined }; | ||
|
||
declare var s: S | ||
|
||
if (s.value !== undefined) { | ||
s; | ||
} | ||
|
||
|
||
//// [50527.js] | ||
"use strict"; | ||
if (s.value !== undefined) { | ||
s; | ||
} |
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/50527.ts === | ||
type S = | ||
>S : Symbol(S, Decl(50527.ts, 0, 0)) | ||
|
||
| { type: 'string', value: string } | ||
>type : Symbol(type, Decl(50527.ts, 1, 3)) | ||
>value : Symbol(value, Decl(50527.ts, 1, 19)) | ||
|
||
| { type: 'number', value: number } | ||
>type : Symbol(type, Decl(50527.ts, 2, 3)) | ||
>value : Symbol(value, Decl(50527.ts, 2, 19)) | ||
|
||
| { type: 'unknown', value: unknown } | ||
>type : Symbol(type, Decl(50527.ts, 3, 3)) | ||
>value : Symbol(value, Decl(50527.ts, 3, 20)) | ||
|
||
| { value: undefined }; | ||
>value : Symbol(value, Decl(50527.ts, 4, 3)) | ||
|
||
declare var s: S | ||
>s : Symbol(s, Decl(50527.ts, 6, 11)) | ||
>S : Symbol(S, Decl(50527.ts, 0, 0)) | ||
|
||
if (s.value !== undefined) { | ||
>s.value : Symbol(value, Decl(50527.ts, 1, 19), Decl(50527.ts, 2, 19), Decl(50527.ts, 3, 20), Decl(50527.ts, 4, 3)) | ||
>s : Symbol(s, Decl(50527.ts, 6, 11)) | ||
>value : Symbol(value, Decl(50527.ts, 1, 19), Decl(50527.ts, 2, 19), Decl(50527.ts, 3, 20), Decl(50527.ts, 4, 3)) | ||
>undefined : Symbol(undefined) | ||
|
||
s; | ||
>s : Symbol(s, Decl(50527.ts, 6, 11)) | ||
} | ||
|
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/50527.ts === | ||
type S = | ||
>S : { type: 'string'; value: string; } | { type: 'number'; value: number; } | { type: 'unknown'; value: unknown; } | { value: undefined; } | ||
|
||
| { type: 'string', value: string } | ||
>type : "string" | ||
>value : string | ||
|
||
| { type: 'number', value: number } | ||
>type : "number" | ||
>value : number | ||
|
||
| { type: 'unknown', value: unknown } | ||
>type : "unknown" | ||
>value : unknown | ||
|
||
| { value: undefined }; | ||
>value : undefined | ||
|
||
declare var s: S | ||
>s : S | ||
|
||
if (s.value !== undefined) { | ||
>s.value !== undefined : boolean | ||
>s.value : unknown | ||
>s : S | ||
>value : unknown | ||
>undefined : undefined | ||
|
||
s; | ||
>s : { type: "string"; value: string; } | { type: "number"; value: number; } | { type: "unknown"; value: unknown; } | ||
} | ||
|
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 | ||
|
||
type S = | ||
| { type: 'string', value: string } | ||
| { type: 'number', value: number } | ||
| { type: 'unknown', value: unknown } | ||
| { value: undefined }; | ||
|
||
declare var s: S | ||
|
||
if (s.value !== undefined) { | ||
s; | ||
} |