mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Add more excess property check tests for unions
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -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" };
|
||||
|
||||
@@ -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" }
|
||||
|
||||
Reference in New Issue
Block a user