Skip to content

Commit 8a7186d

Browse files
committed
Add more excess property check tests for unions
1 parent d04f4a9 commit 8a7186d

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,14 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,1): error TS2322: Type
8686
!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "C"; }'.
8787
!!! error TS2322: Types of property 'tag' are incompatible.
8888
!!! error TS2322: Type '"A"' is not assignable to type '"C"'.
89+
90+
type Overlapping =
91+
| { a: 1, b: 1, first: string }
92+
| { a: 2, second: string }
93+
| { b: 3, third: string }
94+
let over: Overlapping
95+
96+
// these two are not reported because there are two discriminant properties
97+
over = { a: 1, b: 1, first: "ok", second: "error" }
98+
over = { a: 1, b: 1, first: "ok", third: "error" }
8999

tests/baselines/reference/excessPropertyCheckWithUnions.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ amb = { tag: "A", y: 12, extra: 12 }
3939
// the last constituent since assignability error reporting can't find a single best discriminant either.
4040
amb = { tag: "A" }
4141
amb = { tag: "A", z: true }
42+
43+
type Overlapping =
44+
| { a: 1, b: 1, first: string }
45+
| { a: 2, second: string }
46+
| { b: 3, third: string }
47+
let over: Overlapping
48+
49+
// these two are not reported because there are two discriminant properties
50+
over = { a: 1, b: 1, first: "ok", second: "error" }
51+
over = { a: 1, b: 1, first: "ok", third: "error" }
4252

4353

4454
//// [excessPropertyCheckWithUnions.js]
@@ -58,3 +68,7 @@ amb = { tag: "A", y: 12, extra: 12 };
5868
// the last constituent since assignability error reporting can't find a single best discriminant either.
5969
amb = { tag: "A" };
6070
amb = { tag: "A", z: true };
71+
var over;
72+
// these two are not reported because there are two discriminant properties
73+
over = { a: 1, b: 1, first: "ok", second: "error" };
74+
over = { a: 1, b: 1, first: "ok", third: "error" };

tests/cases/compiler/excessPropertyCheckWithUnions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ amb = { tag: "A", y: 12, extra: 12 }
3838
// the last constituent since assignability error reporting can't find a single best discriminant either.
3939
amb = { tag: "A" }
4040
amb = { tag: "A", z: true }
41+
42+
type Overlapping =
43+
| { a: 1, b: 1, first: string }
44+
| { a: 2, second: string }
45+
| { b: 3, third: string }
46+
let over: Overlapping
47+
48+
// these two are not reported because there are two discriminant properties
49+
over = { a: 1, b: 1, first: "ok", second: "error" }
50+
over = { a: 1, b: 1, first: "ok", third: "error" }

0 commit comments

Comments
 (0)