|
| 1 | +=== tests/cases/compiler/excessPropertyCheckWithUnions.ts === |
| 2 | +type ADT = { |
| 3 | +>ADT : Symbol(ADT, Decl(excessPropertyCheckWithUnions.ts, 0, 0)) |
| 4 | + |
| 5 | + tag: "A", |
| 6 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 0, 12)) |
| 7 | + |
| 8 | + a1: string |
| 9 | +>a1 : Symbol(a1, Decl(excessPropertyCheckWithUnions.ts, 1, 13)) |
| 10 | + |
| 11 | +} | { |
| 12 | + tag: "D", |
| 13 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 3, 5)) |
| 14 | + |
| 15 | + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 16 | +>d20 : Symbol(d20, Decl(excessPropertyCheckWithUnions.ts, 4, 13)) |
| 17 | + |
| 18 | +} | { |
| 19 | + tag: "T", |
| 20 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 6, 5)) |
| 21 | +} |
| 22 | +let wrong: ADT = { tag: "T", a1: "extra" } |
| 23 | +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) |
| 24 | +>ADT : Symbol(ADT, Decl(excessPropertyCheckWithUnions.ts, 0, 0)) |
| 25 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 9, 18)) |
| 26 | +>a1 : Symbol(a1, Decl(excessPropertyCheckWithUnions.ts, 9, 28)) |
| 27 | + |
| 28 | +wrong = { tag: "A", d20: 12 } |
| 29 | +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) |
| 30 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 10, 9)) |
| 31 | +>d20 : Symbol(d20, Decl(excessPropertyCheckWithUnions.ts, 10, 19)) |
| 32 | + |
| 33 | +wrong = { tag: "D" } |
| 34 | +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) |
| 35 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 11, 9)) |
| 36 | + |
| 37 | +type Ambiguous = { |
| 38 | +>Ambiguous : Symbol(Ambiguous, Decl(excessPropertyCheckWithUnions.ts, 11, 20)) |
| 39 | + |
| 40 | + tag: "A", |
| 41 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 13, 18)) |
| 42 | + |
| 43 | + x: string |
| 44 | +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 14, 13)) |
| 45 | + |
| 46 | +} | { |
| 47 | + tag: "A", |
| 48 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 16, 5)) |
| 49 | + |
| 50 | + y: number |
| 51 | +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 17, 13)) |
| 52 | + |
| 53 | +} | { |
| 54 | + tag: "B", |
| 55 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 19, 5)) |
| 56 | + |
| 57 | + z: boolean |
| 58 | +>z : Symbol(z, Decl(excessPropertyCheckWithUnions.ts, 20, 13)) |
| 59 | + |
| 60 | +} | { |
| 61 | + tag: "C" |
| 62 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 22, 5)) |
| 63 | +} |
| 64 | +let amb: Ambiguous |
| 65 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 66 | +>Ambiguous : Symbol(Ambiguous, Decl(excessPropertyCheckWithUnions.ts, 11, 20)) |
| 67 | + |
| 68 | +// no error for ambiguous tag, even when it could satisfy both constituents at once |
| 69 | +amb = { tag: "A", x: "hi" } |
| 70 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 71 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 27, 7)) |
| 72 | +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 27, 17)) |
| 73 | + |
| 74 | +amb = { tag: "A", y: 12 } |
| 75 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 76 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 28, 7)) |
| 77 | +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 28, 17)) |
| 78 | + |
| 79 | +amb = { tag: "A", x: "hi", y: 12 } |
| 80 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 81 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 29, 7)) |
| 82 | +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 29, 17)) |
| 83 | +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 29, 26)) |
| 84 | + |
| 85 | +// correctly error on excess property 'extra', even when ambiguous |
| 86 | +amb = { tag: "A", x: "hi", extra: 12 } |
| 87 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 88 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 32, 7)) |
| 89 | +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 32, 17)) |
| 90 | +>extra : Symbol(extra, Decl(excessPropertyCheckWithUnions.ts, 32, 26)) |
| 91 | + |
| 92 | +amb = { tag: "A", y: 12, extra: 12 } |
| 93 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 94 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 33, 7)) |
| 95 | +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 33, 17)) |
| 96 | +>extra : Symbol(extra, Decl(excessPropertyCheckWithUnions.ts, 33, 24)) |
| 97 | + |
| 98 | +// assignability errors still work. |
| 99 | +// But note that the error for `z: true` is the fallback one of reporting on |
| 100 | +// the last constituent since assignability error reporting can't find a single best discriminant either. |
| 101 | +amb = { tag: "A" } |
| 102 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 103 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 38, 7)) |
| 104 | + |
| 105 | +amb = { tag: "A", z: true } |
| 106 | +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) |
| 107 | +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 39, 7)) |
| 108 | +>z : Symbol(z, Decl(excessPropertyCheckWithUnions.ts, 39, 17)) |
| 109 | + |
| 110 | +type Overlapping = |
| 111 | +>Overlapping : Symbol(Overlapping, Decl(excessPropertyCheckWithUnions.ts, 39, 27)) |
| 112 | + |
| 113 | + | { a: 1, b: 1, first: string } |
| 114 | +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 42, 7)) |
| 115 | +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 42, 13)) |
| 116 | +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 42, 19)) |
| 117 | + |
| 118 | + | { a: 2, second: string } |
| 119 | +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 43, 7)) |
| 120 | +>second : Symbol(second, Decl(excessPropertyCheckWithUnions.ts, 43, 13)) |
| 121 | + |
| 122 | + | { b: 3, third: string } |
| 123 | +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 44, 7)) |
| 124 | +>third : Symbol(third, Decl(excessPropertyCheckWithUnions.ts, 44, 13)) |
| 125 | + |
| 126 | +let over: Overlapping |
| 127 | +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) |
| 128 | +>Overlapping : Symbol(Overlapping, Decl(excessPropertyCheckWithUnions.ts, 39, 27)) |
| 129 | + |
| 130 | +// these two are not reported because there are two discriminant properties |
| 131 | +over = { a: 1, b: 1, first: "ok", second: "error" } |
| 132 | +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) |
| 133 | +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 48, 8)) |
| 134 | +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 48, 14)) |
| 135 | +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 48, 20)) |
| 136 | +>second : Symbol(second, Decl(excessPropertyCheckWithUnions.ts, 48, 33)) |
| 137 | + |
| 138 | +over = { a: 1, b: 1, first: "ok", third: "error" } |
| 139 | +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) |
| 140 | +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 49, 8)) |
| 141 | +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 49, 14)) |
| 142 | +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 49, 20)) |
| 143 | +>third : Symbol(third, Decl(excessPropertyCheckWithUnions.ts, 49, 33)) |
| 144 | + |
0 commit comments