forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discriminate types with divergent read/write property types (microsof…
- Loading branch information
Showing
25 changed files
with
2,086 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
76 changes: 76 additions & 0 deletions
76
tests/baselines/reference/discriminateWithDivergentAccessors1.symbols
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,76 @@ | ||
//// [tests/cases/compiler/discriminateWithDivergentAccessors1.ts] //// | ||
|
||
=== discriminateWithDivergentAccessors1.ts === | ||
type WeirdoBox<T> = | ||
>WeirdoBox : Symbol(WeirdoBox, Decl(discriminateWithDivergentAccessors1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 0, 15)) | ||
|
||
| { get done(): false; set done(v: T | null) } | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 1, 5), Decl(discriminateWithDivergentAccessors1.ts, 1, 24)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 1, 5), Decl(discriminateWithDivergentAccessors1.ts, 1, 24)) | ||
>v : Symbol(v, Decl(discriminateWithDivergentAccessors1.ts, 1, 34)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 0, 15)) | ||
|
||
| { get done(): true; set done(v: T | null); value: T }; | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 2, 5), Decl(discriminateWithDivergentAccessors1.ts, 2, 23)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 2, 5), Decl(discriminateWithDivergentAccessors1.ts, 2, 23)) | ||
>v : Symbol(v, Decl(discriminateWithDivergentAccessors1.ts, 2, 33)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 0, 15)) | ||
>value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 2, 46)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 0, 15)) | ||
|
||
declare const weirdoBox: WeirdoBox<number>; | ||
>weirdoBox : Symbol(weirdoBox, Decl(discriminateWithDivergentAccessors1.ts, 4, 13)) | ||
>WeirdoBox : Symbol(WeirdoBox, Decl(discriminateWithDivergentAccessors1.ts, 0, 0)) | ||
|
||
if (weirdoBox.done) { | ||
>weirdoBox.done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 1, 5), Decl(discriminateWithDivergentAccessors1.ts, 1, 24), Decl(discriminateWithDivergentAccessors1.ts, 2, 5), Decl(discriminateWithDivergentAccessors1.ts, 2, 23)) | ||
>weirdoBox : Symbol(weirdoBox, Decl(discriminateWithDivergentAccessors1.ts, 4, 13)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 1, 5), Decl(discriminateWithDivergentAccessors1.ts, 1, 24), Decl(discriminateWithDivergentAccessors1.ts, 2, 5), Decl(discriminateWithDivergentAccessors1.ts, 2, 23)) | ||
|
||
weirdoBox.value; | ||
>weirdoBox.value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 2, 46)) | ||
>weirdoBox : Symbol(weirdoBox, Decl(discriminateWithDivergentAccessors1.ts, 4, 13)) | ||
>value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 2, 46)) | ||
} | ||
|
||
type WeirdoBox2<T> = | ||
>WeirdoBox2 : Symbol(WeirdoBox2, Decl(discriminateWithDivergentAccessors1.ts, 8, 1)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 10, 16)) | ||
|
||
| { get done(): false; set done(v: T | null) } | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 11, 5), Decl(discriminateWithDivergentAccessors1.ts, 11, 24)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 11, 5), Decl(discriminateWithDivergentAccessors1.ts, 11, 24)) | ||
>v : Symbol(v, Decl(discriminateWithDivergentAccessors1.ts, 11, 34)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 10, 16)) | ||
|
||
| { get done(): true; set done(v: T | null); value: T } | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 12, 5), Decl(discriminateWithDivergentAccessors1.ts, 12, 23)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 12, 5), Decl(discriminateWithDivergentAccessors1.ts, 12, 23)) | ||
>v : Symbol(v, Decl(discriminateWithDivergentAccessors1.ts, 12, 33)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 10, 16)) | ||
>value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 12, 46)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 10, 16)) | ||
|
||
| { get done(): true; set done(v: T | null | undefined); value: number }; | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 13, 5), Decl(discriminateWithDivergentAccessors1.ts, 13, 23)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 13, 5), Decl(discriminateWithDivergentAccessors1.ts, 13, 23)) | ||
>v : Symbol(v, Decl(discriminateWithDivergentAccessors1.ts, 13, 33)) | ||
>T : Symbol(T, Decl(discriminateWithDivergentAccessors1.ts, 10, 16)) | ||
>value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 13, 58)) | ||
|
||
declare const weirdoBox2: WeirdoBox2<string>; | ||
>weirdoBox2 : Symbol(weirdoBox2, Decl(discriminateWithDivergentAccessors1.ts, 15, 13)) | ||
>WeirdoBox2 : Symbol(WeirdoBox2, Decl(discriminateWithDivergentAccessors1.ts, 8, 1)) | ||
|
||
if (weirdoBox2.done) { | ||
>weirdoBox2.done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 11, 5), Decl(discriminateWithDivergentAccessors1.ts, 11, 24), Decl(discriminateWithDivergentAccessors1.ts, 12, 5), Decl(discriminateWithDivergentAccessors1.ts, 12, 23), Decl(discriminateWithDivergentAccessors1.ts, 13, 5) ... and 1 more) | ||
>weirdoBox2 : Symbol(weirdoBox2, Decl(discriminateWithDivergentAccessors1.ts, 15, 13)) | ||
>done : Symbol(done, Decl(discriminateWithDivergentAccessors1.ts, 11, 5), Decl(discriminateWithDivergentAccessors1.ts, 11, 24), Decl(discriminateWithDivergentAccessors1.ts, 12, 5), Decl(discriminateWithDivergentAccessors1.ts, 12, 23), Decl(discriminateWithDivergentAccessors1.ts, 13, 5) ... and 1 more) | ||
|
||
weirdoBox2.value; | ||
>weirdoBox2.value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 12, 46), Decl(discriminateWithDivergentAccessors1.ts, 13, 58)) | ||
>weirdoBox2 : Symbol(weirdoBox2, Decl(discriminateWithDivergentAccessors1.ts, 15, 13)) | ||
>value : Symbol(value, Decl(discriminateWithDivergentAccessors1.ts, 12, 46), Decl(discriminateWithDivergentAccessors1.ts, 13, 58)) | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/discriminateWithDivergentAccessors1.types
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,70 @@ | ||
//// [tests/cases/compiler/discriminateWithDivergentAccessors1.ts] //// | ||
|
||
=== discriminateWithDivergentAccessors1.ts === | ||
type WeirdoBox<T> = | ||
>WeirdoBox : WeirdoBox<T> | ||
|
||
| { get done(): false; set done(v: T | null) } | ||
>done : false | ||
>false : false | ||
>done : false | ||
>v : T | null | ||
|
||
| { get done(): true; set done(v: T | null); value: T }; | ||
>done : true | ||
>true : true | ||
>done : true | ||
>v : T | null | ||
>value : T | ||
|
||
declare const weirdoBox: WeirdoBox<number>; | ||
>weirdoBox : WeirdoBox<number> | ||
|
||
if (weirdoBox.done) { | ||
>weirdoBox.done : boolean | ||
>weirdoBox : WeirdoBox<number> | ||
>done : boolean | ||
|
||
weirdoBox.value; | ||
>weirdoBox.value : number | ||
>weirdoBox : { done: true; value: number; } | ||
>value : number | ||
} | ||
|
||
type WeirdoBox2<T> = | ||
>WeirdoBox2 : WeirdoBox2<T> | ||
|
||
| { get done(): false; set done(v: T | null) } | ||
>done : false | ||
>false : false | ||
>done : false | ||
>v : T | null | ||
|
||
| { get done(): true; set done(v: T | null); value: T } | ||
>done : true | ||
>true : true | ||
>done : true | ||
>v : T | null | ||
>value : T | ||
|
||
| { get done(): true; set done(v: T | null | undefined); value: number }; | ||
>done : true | ||
>true : true | ||
>done : true | ||
>v : T | null | undefined | ||
>value : number | ||
|
||
declare const weirdoBox2: WeirdoBox2<string>; | ||
>weirdoBox2 : WeirdoBox2<string> | ||
|
||
if (weirdoBox2.done) { | ||
>weirdoBox2.done : boolean | ||
>weirdoBox2 : WeirdoBox2<string> | ||
>done : boolean | ||
|
||
weirdoBox2.value; | ||
>weirdoBox2.value : string | number | ||
>weirdoBox2 : { done: true; value: string; } | { done: true; value: number; } | ||
>value : string | number | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...nes/reference/discriminateWithOptionalProperty1(exactoptionalpropertytypes=false).symbols
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,26 @@ | ||
//// [tests/cases/compiler/discriminateWithOptionalProperty1.ts] //// | ||
|
||
=== discriminateWithOptionalProperty1.ts === | ||
type Box<T> = { done?: false } | { done: true; value: T }; | ||
>Box : Symbol(Box, Decl(discriminateWithOptionalProperty1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(discriminateWithOptionalProperty1.ts, 0, 9)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
>value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
>T : Symbol(T, Decl(discriminateWithOptionalProperty1.ts, 0, 9)) | ||
|
||
declare const box: Box<number>; | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>Box : Symbol(Box, Decl(discriminateWithOptionalProperty1.ts, 0, 0)) | ||
|
||
if (box.done) { | ||
>box.done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15), Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15), Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
|
||
box.value; | ||
>box.value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...lines/reference/discriminateWithOptionalProperty1(exactoptionalpropertytypes=false).types
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,25 @@ | ||
//// [tests/cases/compiler/discriminateWithOptionalProperty1.ts] //// | ||
|
||
=== discriminateWithOptionalProperty1.ts === | ||
type Box<T> = { done?: false } | { done: true; value: T }; | ||
>Box : Box<T> | ||
>done : false | undefined | ||
>false : false | ||
>done : true | ||
>true : true | ||
>value : T | ||
|
||
declare const box: Box<number>; | ||
>box : Box<number> | ||
|
||
if (box.done) { | ||
>box.done : boolean | undefined | ||
>box : Box<number> | ||
>done : boolean | undefined | ||
|
||
box.value; | ||
>box.value : number | ||
>box : { done: true; value: number; } | ||
>value : number | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...ines/reference/discriminateWithOptionalProperty1(exactoptionalpropertytypes=true).symbols
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,26 @@ | ||
//// [tests/cases/compiler/discriminateWithOptionalProperty1.ts] //// | ||
|
||
=== discriminateWithOptionalProperty1.ts === | ||
type Box<T> = { done?: false } | { done: true; value: T }; | ||
>Box : Symbol(Box, Decl(discriminateWithOptionalProperty1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(discriminateWithOptionalProperty1.ts, 0, 9)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
>value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
>T : Symbol(T, Decl(discriminateWithOptionalProperty1.ts, 0, 9)) | ||
|
||
declare const box: Box<number>; | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>Box : Symbol(Box, Decl(discriminateWithOptionalProperty1.ts, 0, 0)) | ||
|
||
if (box.done) { | ||
>box.done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15), Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>done : Symbol(done, Decl(discriminateWithOptionalProperty1.ts, 0, 15), Decl(discriminateWithOptionalProperty1.ts, 0, 34)) | ||
|
||
box.value; | ||
>box.value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
>box : Symbol(box, Decl(discriminateWithOptionalProperty1.ts, 2, 13)) | ||
>value : Symbol(value, Decl(discriminateWithOptionalProperty1.ts, 0, 46)) | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...elines/reference/discriminateWithOptionalProperty1(exactoptionalpropertytypes=true).types
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,25 @@ | ||
//// [tests/cases/compiler/discriminateWithOptionalProperty1.ts] //// | ||
|
||
=== discriminateWithOptionalProperty1.ts === | ||
type Box<T> = { done?: false } | { done: true; value: T }; | ||
>Box : Box<T> | ||
>done : false | undefined | ||
>false : false | ||
>done : true | ||
>true : true | ||
>value : T | ||
|
||
declare const box: Box<number>; | ||
>box : Box<number> | ||
|
||
if (box.done) { | ||
>box.done : boolean | undefined | ||
>box : Box<number> | ||
>done : boolean | undefined | ||
|
||
box.value; | ||
>box.value : number | ||
>box : { done: true; value: number; } | ||
>value : number | ||
} | ||
|
Oops, something went wrong.