-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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: 6aaf984 Allow intersections (and substitutions) to be checks against discriminable unions Co-authored-by: Wesley Wigham <wwigham@gmail.com>
- Loading branch information
1 parent
fb86896
commit ae8dc2f
Showing
5 changed files
with
126 additions
and
3 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
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/discriminableUnionWithIntersectedMembers.js
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,21 @@ | ||
//// [discriminableUnionWithIntersectedMembers.ts] | ||
// regression test for https://github.com/microsoft/TypeScript/issues/33243 | ||
type X = | ||
| { x: 'x', y: number } & { y: number } | ||
| { x: 'y', y: number, z?: boolean } & { y: number } | ||
|
||
// error | ||
const x: X = 4 as any as { x: 'x' | 'y', y: number }; | ||
|
||
type Y = | ||
| { x: 'x', y: number } | ||
| { x: 'y', y: number, z?: boolean } | ||
|
||
// no error | ||
const y: Y = 4 as any as { x: 'x' | 'y', y: number }; | ||
|
||
//// [discriminableUnionWithIntersectedMembers.js] | ||
// error | ||
var x = 4; | ||
// no error | ||
var y = 4; |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/discriminableUnionWithIntersectedMembers.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,42 @@ | ||
=== tests/cases/compiler/discriminableUnionWithIntersectedMembers.ts === | ||
// regression test for https://github.com/microsoft/TypeScript/issues/33243 | ||
type X = | ||
>X : Symbol(X, Decl(discriminableUnionWithIntersectedMembers.ts, 0, 0)) | ||
|
||
| { x: 'x', y: number } & { y: number } | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 2, 4)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 2, 12)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 2, 28)) | ||
|
||
| { x: 'y', y: number, z?: boolean } & { y: number } | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 3, 4)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 3, 12)) | ||
>z : Symbol(z, Decl(discriminableUnionWithIntersectedMembers.ts, 3, 23)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 3, 41)) | ||
|
||
// error | ||
const x: X = 4 as any as { x: 'x' | 'y', y: number }; | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 6, 5)) | ||
>X : Symbol(X, Decl(discriminableUnionWithIntersectedMembers.ts, 0, 0)) | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 6, 26)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 6, 40)) | ||
|
||
type Y = | ||
>Y : Symbol(Y, Decl(discriminableUnionWithIntersectedMembers.ts, 6, 53)) | ||
|
||
| { x: 'x', y: number } | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 9, 4)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 9, 12)) | ||
|
||
| { x: 'y', y: number, z?: boolean } | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 10, 4)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 10, 12)) | ||
>z : Symbol(z, Decl(discriminableUnionWithIntersectedMembers.ts, 10, 23)) | ||
|
||
// no error | ||
const y: Y = 4 as any as { x: 'x' | 'y', y: number }; | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 13, 5)) | ||
>Y : Symbol(Y, Decl(discriminableUnionWithIntersectedMembers.ts, 6, 53)) | ||
>x : Symbol(x, Decl(discriminableUnionWithIntersectedMembers.ts, 13, 26)) | ||
>y : Symbol(y, Decl(discriminableUnionWithIntersectedMembers.ts, 13, 40)) | ||
|
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/discriminableUnionWithIntersectedMembers.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,46 @@ | ||
=== tests/cases/compiler/discriminableUnionWithIntersectedMembers.ts === | ||
// regression test for https://github.com/microsoft/TypeScript/issues/33243 | ||
type X = | ||
>X : X | ||
|
||
| { x: 'x', y: number } & { y: number } | ||
>x : "x" | ||
>y : number | ||
>y : number | ||
|
||
| { x: 'y', y: number, z?: boolean } & { y: number } | ||
>x : "y" | ||
>y : number | ||
>z : boolean | ||
>y : number | ||
|
||
// error | ||
const x: X = 4 as any as { x: 'x' | 'y', y: number }; | ||
>x : X | ||
>4 as any as { x: 'x' | 'y', y: number } : { x: "x" | "y"; y: number; } | ||
>4 as any : any | ||
>4 : 4 | ||
>x : "x" | "y" | ||
>y : number | ||
|
||
type Y = | ||
>Y : Y | ||
|
||
| { x: 'x', y: number } | ||
>x : "x" | ||
>y : number | ||
|
||
| { x: 'y', y: number, z?: boolean } | ||
>x : "y" | ||
>y : number | ||
>z : boolean | ||
|
||
// no error | ||
const y: Y = 4 as any as { x: 'x' | 'y', y: number }; | ||
>y : Y | ||
>4 as any as { x: 'x' | 'y', y: number } : { x: "x" | "y"; y: number; } | ||
>4 as any : any | ||
>4 : 4 | ||
>x : "x" | "y" | ||
>y : number | ||
|
14 changes: 14 additions & 0 deletions
14
tests/cases/compiler/discriminableUnionWithIntersectedMembers.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,14 @@ | ||
// regression test for https://github.com/microsoft/TypeScript/issues/33243 | ||
type X = | ||
| { x: 'x', y: number } & { y: number } | ||
| { x: 'y', y: number, z?: boolean } & { y: number } | ||
|
||
// error | ||
const x: X = 4 as any as { x: 'x' | 'y', y: number }; | ||
|
||
type Y = | ||
| { x: 'x', y: number } | ||
| { x: 'y', y: number, z?: boolean } | ||
|
||
// no error | ||
const y: Y = 4 as any as { x: 'x' | 'y', y: number }; |