tests/cases/compiler/excessPropertyCheckWithUnions.ts(10,30): error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'.
  Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(11,21): error TS2322: Type '{ tag: "A"; d20: number; }' is not assignable to type 'ADT'.
  Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(12,1): error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'.
  Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'.
    Property 'd20' is missing in type '{ tag: "D"; }'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(33,28): error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'.
  Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(34,26): error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'.
  Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(39,1): error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'.
  Type '{ tag: "A"; }' is not assignable to type '{ tag: "C"; }'.
    Types of property 'tag' are incompatible.
      Type '"A"' is not assignable to type '"C"'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,1): error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'.
  Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "C"; }'.
    Types of property 'tag' are incompatible.
      Type '"A"' is not assignable to type '"C"'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(49,35): error TS2322: Type '{ a: 1; b: 1; first: string; second: string; }' is not assignable to type 'Overlapping'.
  Object literal may only specify known properties, and 'second' does not exist in type '{ a: 1; b: 1; first: string; }'.
tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type '{ a: 1; b: 1; first: string; third: string; }' is not assignable to type 'Overlapping'.
  Object literal may only specify known properties, and 'third' does not exist in type '{ a: 1; b: 1; first: string; }'.


==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (9 errors) ====
    type ADT = {
        tag: "A",
        a1: string
    } | {
        tag: "D",
        d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
    } | {
        tag: "T",
    }
    let wrong: ADT = { tag: "T", a1: "extra" }
                                 ~~~~~~~~~~~
!!! error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'.
!!! error TS2322:   Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'.
    wrong = { tag: "A", d20: 12 }
                        ~~~~~~~
!!! error TS2322: Type '{ tag: "A"; d20: number; }' is not assignable to type 'ADT'.
!!! error TS2322:   Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'.
    wrong = { tag: "D" }
    ~~~~~
!!! error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'.
!!! error TS2322:   Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'.
!!! error TS2322:     Property 'd20' is missing in type '{ tag: "D"; }'.
    
    type Ambiguous = {
        tag: "A",
        x: string
    } | {
        tag: "A",
        y: number
    } | {
        tag: "B",
        z: boolean
    } | {
        tag: "C"
    }
    let amb: Ambiguous
    // no error for ambiguous tag, even when it could satisfy both constituents at once
    amb = { tag: "A", x: "hi" }
    amb = { tag: "A", y: 12 }
    amb = { tag: "A", x: "hi", y: 12 }
    
    // correctly error on excess property 'extra', even when ambiguous
    amb = { tag: "A", x: "hi", extra: 12 }
                               ~~~~~~~~~
!!! error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'.
!!! error TS2322:   Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
    amb = { tag: "A", y: 12, extra: 12 }
                             ~~~~~~~~~
!!! error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'.
!!! error TS2322:   Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
    
    // assignability errors still work.
    // But note that the error for `z: true` is the fallback one of reporting on
    // the last constituent since assignability error reporting can't find a single best discriminant either.
    amb = { tag: "A" }
    ~~~
!!! error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'.
!!! error TS2322:   Type '{ tag: "A"; }' 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"'.
    amb = { tag: "A", z: true }
    ~~~
!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'.
!!! 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 still errors despite their doubled up discriminants
    over = { a: 1, b: 1, first: "ok", second: "error" }
                                      ~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ a: 1; b: 1; first: string; second: string; }' is not assignable to type 'Overlapping'.
!!! error TS2322:   Object literal may only specify known properties, and 'second' does not exist in type '{ a: 1; b: 1; first: string; }'.
    over = { a: 1, b: 1, first: "ok", third: "error" }
                                      ~~~~~~~~~~~~~~
!!! error TS2322: Type '{ a: 1; b: 1; first: string; third: string; }' is not assignable to type 'Overlapping'.
!!! error TS2322:   Object literal may only specify known properties, and 'third' does not exist in type '{ a: 1; b: 1; first: string; }'.
    
    // Freshness disappears after spreading a union
    declare let t0: { a: any, b: any } | { d: any, e: any }
    declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any }
    let t2 = { ...t1 }
    t0 = t2
    