diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt index 9714c90ba61..3b7e5a787d2 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt @@ -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" } \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.js b/tests/baselines/reference/excessPropertyCheckWithUnions.js index fb0a5a6f819..c6da660b52d 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.js +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.js @@ -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" }; diff --git a/tests/cases/compiler/excessPropertyCheckWithUnions.ts b/tests/cases/compiler/excessPropertyCheckWithUnions.ts index 51f36d137fd..9a7968fe511 100644 --- a/tests/cases/compiler/excessPropertyCheckWithUnions.ts +++ b/tests/cases/compiler/excessPropertyCheckWithUnions.ts @@ -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" }