|
| 1 | +=== tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts === |
| 2 | +// Repro from #32657 |
| 3 | + |
| 4 | +interface Base<T> { |
| 5 | +>Base : Symbol(Base, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 0, 0)) |
| 6 | +>T : Symbol(T, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 2, 15)) |
| 7 | + |
| 8 | + value: T; |
| 9 | +>value : Symbol(Base.value, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 2, 19)) |
| 10 | +>T : Symbol(T, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 2, 15)) |
| 11 | +} |
| 12 | + |
| 13 | +interface Int extends Base<number> { |
| 14 | +>Int : Symbol(Int, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 4, 1)) |
| 15 | +>Base : Symbol(Base, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 0, 0)) |
| 16 | + |
| 17 | + type: "integer"; |
| 18 | +>type : Symbol(Int.type, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 6, 36)) |
| 19 | + |
| 20 | + multipleOf?: number; |
| 21 | +>multipleOf : Symbol(Int.multipleOf, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 7, 20)) |
| 22 | +} |
| 23 | + |
| 24 | +interface Float extends Base<number> { |
| 25 | +>Float : Symbol(Float, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 9, 1)) |
| 26 | +>Base : Symbol(Base, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 0, 0)) |
| 27 | + |
| 28 | + type: "number"; |
| 29 | +>type : Symbol(Float.type, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 11, 38)) |
| 30 | +} |
| 31 | + |
| 32 | +interface Str extends Base<string> { |
| 33 | +>Str : Symbol(Str, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 13, 1)) |
| 34 | +>Base : Symbol(Base, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 0, 0)) |
| 35 | + |
| 36 | + type: "string"; |
| 37 | +>type : Symbol(Str.type, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 15, 36)) |
| 38 | + |
| 39 | + format?: string; |
| 40 | +>format : Symbol(Str.format, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 16, 19)) |
| 41 | +} |
| 42 | + |
| 43 | +interface Bool extends Base<boolean> { |
| 44 | +>Bool : Symbol(Bool, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 18, 1)) |
| 45 | +>Base : Symbol(Base, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 0, 0)) |
| 46 | + |
| 47 | + type: "boolean"; |
| 48 | +>type : Symbol(Bool.type, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 20, 38)) |
| 49 | +} |
| 50 | + |
| 51 | +type Primitive = Int | Float | Str | Bool; |
| 52 | +>Primitive : Symbol(Primitive, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 22, 1)) |
| 53 | +>Int : Symbol(Int, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 4, 1)) |
| 54 | +>Float : Symbol(Float, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 9, 1)) |
| 55 | +>Str : Symbol(Str, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 13, 1)) |
| 56 | +>Bool : Symbol(Bool, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 18, 1)) |
| 57 | + |
| 58 | +const foo: Primitive = { |
| 59 | +>foo : Symbol(foo, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 26, 5)) |
| 60 | +>Primitive : Symbol(Primitive, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 22, 1)) |
| 61 | + |
| 62 | + type: "number", |
| 63 | +>type : Symbol(type, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 26, 24)) |
| 64 | + |
| 65 | + value: 10, |
| 66 | +>value : Symbol(value, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 27, 19)) |
| 67 | + |
| 68 | + multipleOf: 5, // excess property |
| 69 | +>multipleOf : Symbol(multipleOf, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 28, 14)) |
| 70 | + |
| 71 | + format: "what?" |
| 72 | +>format : Symbol(format, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 29, 18)) |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +type DisjointDiscriminants = { p1: 'left'; p2: true; p3: number } | { p1: 'right'; p2: false; p4: string } | { p1: 'left'; p2: boolean }; |
| 77 | +>DisjointDiscriminants : Symbol(DisjointDiscriminants, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 31, 1)) |
| 78 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 30)) |
| 79 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 42)) |
| 80 | +>p3 : Symbol(p3, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 52)) |
| 81 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 69)) |
| 82 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 82)) |
| 83 | +>p4 : Symbol(p4, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 93)) |
| 84 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 110)) |
| 85 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 34, 122)) |
| 86 | + |
| 87 | +// This has excess error because variant three is the only applicable case. |
| 88 | +const a: DisjointDiscriminants = { |
| 89 | +>a : Symbol(a, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 37, 5)) |
| 90 | +>DisjointDiscriminants : Symbol(DisjointDiscriminants, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 31, 1)) |
| 91 | + |
| 92 | + p1: 'left', |
| 93 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 37, 34)) |
| 94 | + |
| 95 | + p2: false, |
| 96 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 38, 15)) |
| 97 | + |
| 98 | + p3: 42, |
| 99 | +>p3 : Symbol(p3, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 39, 14)) |
| 100 | + |
| 101 | + p4: "hello" |
| 102 | +>p4 : Symbol(p4, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 40, 11)) |
| 103 | + |
| 104 | +}; |
| 105 | + |
| 106 | +// This has no excess error because variant one and three are both applicable. |
| 107 | +const b: DisjointDiscriminants = { |
| 108 | +>b : Symbol(b, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 45, 5)) |
| 109 | +>DisjointDiscriminants : Symbol(DisjointDiscriminants, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 31, 1)) |
| 110 | + |
| 111 | + p1: 'left', |
| 112 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 45, 34)) |
| 113 | + |
| 114 | + p2: true, |
| 115 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 46, 15)) |
| 116 | + |
| 117 | + p3: 42, |
| 118 | +>p3 : Symbol(p3, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 47, 13)) |
| 119 | + |
| 120 | + p4: "hello" |
| 121 | +>p4 : Symbol(p4, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 48, 11)) |
| 122 | + |
| 123 | +}; |
| 124 | + |
| 125 | +// This has excess error because variant two is the only applicable case |
| 126 | +const c: DisjointDiscriminants = { |
| 127 | +>c : Symbol(c, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 53, 5)) |
| 128 | +>DisjointDiscriminants : Symbol(DisjointDiscriminants, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 31, 1)) |
| 129 | + |
| 130 | + p1: 'right', |
| 131 | +>p1 : Symbol(p1, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 53, 34)) |
| 132 | + |
| 133 | + p2: false, |
| 134 | +>p2 : Symbol(p2, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 54, 16)) |
| 135 | + |
| 136 | + p3: 42, |
| 137 | +>p3 : Symbol(p3, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 55, 14)) |
| 138 | + |
| 139 | + p4: "hello" |
| 140 | +>p4 : Symbol(p4, Decl(excessPropertyCheckWithMultipleDiscriminants.ts, 56, 11)) |
| 141 | + |
| 142 | +}; |
| 143 | + |
0 commit comments