Add more excess property check tests for unions

This commit is contained in:
Nathan Shively-Sanders
2017-06-09 15:47:57 -07:00
parent d04f4a93a7
commit 8a7186d190
3 changed files with 34 additions and 0 deletions

View File

@@ -86,4 +86,14 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,1): error TS2322: Type
!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "C"; }'.
!!! error TS2322: Types of property 'tag' are incompatible.
!!! error TS2322: Type '"A"' is not assignable to type '"C"'.
type Overlapping =
| { a: 1, b: 1, first: string }
| { a: 2, second: string }
| { b: 3, third: string }
let over: Overlapping
// these two are not reported because there are two discriminant properties
over = { a: 1, b: 1, first: "ok", second: "error" }
over = { a: 1, b: 1, first: "ok", third: "error" }

View File

@@ -39,6 +39,16 @@ amb = { tag: "A", y: 12, extra: 12 }
// the last constituent since assignability error reporting can't find a single best discriminant either.
amb = { tag: "A" }
amb = { tag: "A", z: true }
type Overlapping =
| { a: 1, b: 1, first: string }
| { a: 2, second: string }
| { b: 3, third: string }
let over: Overlapping
// these two are not reported because there are two discriminant properties
over = { a: 1, b: 1, first: "ok", second: "error" }
over = { a: 1, b: 1, first: "ok", third: "error" }
//// [excessPropertyCheckWithUnions.js]
@@ -58,3 +68,7 @@ amb = { tag: "A", y: 12, extra: 12 };
// the last constituent since assignability error reporting can't find a single best discriminant either.
amb = { tag: "A" };
amb = { tag: "A", z: true };
var over;
// these two are not reported because there are two discriminant properties
over = { a: 1, b: 1, first: "ok", second: "error" };
over = { a: 1, b: 1, first: "ok", third: "error" };

View File

@@ -38,3 +38,13 @@ amb = { tag: "A", y: 12, extra: 12 }
// the last constituent since assignability error reporting can't find a single best discriminant either.
amb = { tag: "A" }
amb = { tag: "A", z: true }
type Overlapping =
| { a: 1, b: 1, first: string }
| { a: 2, second: string }
| { b: 3, third: string }
let over: Overlapping
// these two are not reported because there are two discriminant properties
over = { a: 1, b: 1, first: "ok", second: "error" }
over = { a: 1, b: 1, first: "ok", third: "error" }