|
| 1 | +=== tests/cases/compiler/narrowingUnionWithBang.ts === |
| 2 | +type WorkingType = { |
| 3 | +>WorkingType : Symbol(WorkingType, Decl(narrowingUnionWithBang.ts, 0, 0)) |
| 4 | + |
| 5 | + thing?: |
| 6 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 7 | + |
| 8 | + { name: 'Error1', message: string } | |
| 9 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 2, 5)) |
| 10 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 2, 21)) |
| 11 | + |
| 12 | + { name: 'Error2', message: string } | |
| 13 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 3, 5)) |
| 14 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 3, 21)) |
| 15 | + |
| 16 | + { name: 'Error3', message: string } | |
| 17 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 4, 5)) |
| 18 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 4, 21)) |
| 19 | + |
| 20 | + { name: 'Error4', message: string } | |
| 21 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 5, 5)) |
| 22 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 5, 21)) |
| 23 | + |
| 24 | + { name: 'Error5', message: string } | |
| 25 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 6, 5)) |
| 26 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 6, 21)) |
| 27 | + |
| 28 | + { name: 'Error6', message: string } | |
| 29 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 7, 5)) |
| 30 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 7, 21)) |
| 31 | + |
| 32 | + { name: 'Error7', message: string } | |
| 33 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 8, 5)) |
| 34 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 8, 21)) |
| 35 | + |
| 36 | + { name: 'Error8', message: string } | |
| 37 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 9, 5)) |
| 38 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 9, 21)) |
| 39 | + |
| 40 | + { name: 'Error9', message: string } | |
| 41 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 10, 5)) |
| 42 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 10, 21)) |
| 43 | + |
| 44 | + { name: 'Correct', id: string } |
| 45 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 11, 5)) |
| 46 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 11, 22)) |
| 47 | + |
| 48 | +}; |
| 49 | +const working: WorkingType = null as unknown as WorkingType; |
| 50 | +>working : Symbol(working, Decl(narrowingUnionWithBang.ts, 13, 5)) |
| 51 | +>WorkingType : Symbol(WorkingType, Decl(narrowingUnionWithBang.ts, 0, 0)) |
| 52 | +>WorkingType : Symbol(WorkingType, Decl(narrowingUnionWithBang.ts, 0, 0)) |
| 53 | + |
| 54 | +if (working.thing!.name !== "Correct") { |
| 55 | +>working.thing!.name : Symbol(name, Decl(narrowingUnionWithBang.ts, 2, 5), Decl(narrowingUnionWithBang.ts, 3, 5), Decl(narrowingUnionWithBang.ts, 4, 5), Decl(narrowingUnionWithBang.ts, 5, 5), Decl(narrowingUnionWithBang.ts, 6, 5) ... and 5 more) |
| 56 | +>working.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 57 | +>working : Symbol(working, Decl(narrowingUnionWithBang.ts, 13, 5)) |
| 58 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 59 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 2, 5), Decl(narrowingUnionWithBang.ts, 3, 5), Decl(narrowingUnionWithBang.ts, 4, 5), Decl(narrowingUnionWithBang.ts, 5, 5), Decl(narrowingUnionWithBang.ts, 6, 5) ... and 5 more) |
| 60 | + |
| 61 | + console.log(working.thing!.message) |
| 62 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 63 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 64 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 65 | +>working.thing!.message : Symbol(message, Decl(narrowingUnionWithBang.ts, 2, 21), Decl(narrowingUnionWithBang.ts, 3, 21), Decl(narrowingUnionWithBang.ts, 4, 21), Decl(narrowingUnionWithBang.ts, 5, 21), Decl(narrowingUnionWithBang.ts, 6, 21) ... and 4 more) |
| 66 | +>working.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 67 | +>working : Symbol(working, Decl(narrowingUnionWithBang.ts, 13, 5)) |
| 68 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 69 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 2, 21), Decl(narrowingUnionWithBang.ts, 3, 21), Decl(narrowingUnionWithBang.ts, 4, 21), Decl(narrowingUnionWithBang.ts, 5, 21), Decl(narrowingUnionWithBang.ts, 6, 21) ... and 4 more) |
| 70 | + |
| 71 | +} else { |
| 72 | + console.log(working.thing!.id); |
| 73 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 74 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 75 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 76 | +>working.thing!.id : Symbol(id, Decl(narrowingUnionWithBang.ts, 11, 22)) |
| 77 | +>working.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 78 | +>working : Symbol(working, Decl(narrowingUnionWithBang.ts, 13, 5)) |
| 79 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 0, 20)) |
| 80 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 11, 22)) |
| 81 | +} |
| 82 | + |
| 83 | +type BorkedType = { |
| 84 | +>BorkedType : Symbol(BorkedType, Decl(narrowingUnionWithBang.ts, 18, 1)) |
| 85 | + |
| 86 | + thing?: |
| 87 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 88 | + |
| 89 | + { name: 'Error1', message: string } | |
| 90 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 22, 5)) |
| 91 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 22, 21)) |
| 92 | + |
| 93 | + { name: 'Error2', message: string } | |
| 94 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 23, 5)) |
| 95 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 23, 21)) |
| 96 | + |
| 97 | + { name: 'Error3', message: string } | |
| 98 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 24, 5)) |
| 99 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 24, 21)) |
| 100 | + |
| 101 | + { name: 'Error4', message: string } | |
| 102 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 25, 5)) |
| 103 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 25, 21)) |
| 104 | + |
| 105 | + { name: 'Error5', message: string } | |
| 106 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 26, 5)) |
| 107 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 26, 21)) |
| 108 | + |
| 109 | + { name: 'Error6', message: string } | |
| 110 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 27, 5)) |
| 111 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 27, 21)) |
| 112 | + |
| 113 | + { name: 'Error7', message: string } | |
| 114 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 28, 5)) |
| 115 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 28, 21)) |
| 116 | + |
| 117 | + { name: 'Error8', message: string } | |
| 118 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 29, 5)) |
| 119 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 29, 21)) |
| 120 | + |
| 121 | + { name: 'Correct', id: string } |
| 122 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 30, 5)) |
| 123 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 30, 22)) |
| 124 | + |
| 125 | +}; |
| 126 | +const borked: BorkedType = null as unknown as BorkedType; |
| 127 | +>borked : Symbol(borked, Decl(narrowingUnionWithBang.ts, 32, 5)) |
| 128 | +>BorkedType : Symbol(BorkedType, Decl(narrowingUnionWithBang.ts, 18, 1)) |
| 129 | +>BorkedType : Symbol(BorkedType, Decl(narrowingUnionWithBang.ts, 18, 1)) |
| 130 | + |
| 131 | +if (borked.thing!.name !== "Correct") { |
| 132 | +>borked.thing!.name : Symbol(name, Decl(narrowingUnionWithBang.ts, 22, 5), Decl(narrowingUnionWithBang.ts, 23, 5), Decl(narrowingUnionWithBang.ts, 24, 5), Decl(narrowingUnionWithBang.ts, 25, 5), Decl(narrowingUnionWithBang.ts, 26, 5) ... and 4 more) |
| 133 | +>borked.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 134 | +>borked : Symbol(borked, Decl(narrowingUnionWithBang.ts, 32, 5)) |
| 135 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 136 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 22, 5), Decl(narrowingUnionWithBang.ts, 23, 5), Decl(narrowingUnionWithBang.ts, 24, 5), Decl(narrowingUnionWithBang.ts, 25, 5), Decl(narrowingUnionWithBang.ts, 26, 5) ... and 4 more) |
| 137 | + |
| 138 | + console.log(borked.thing!.message); |
| 139 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 140 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 141 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 142 | +>borked.thing!.message : Symbol(message, Decl(narrowingUnionWithBang.ts, 22, 21), Decl(narrowingUnionWithBang.ts, 23, 21), Decl(narrowingUnionWithBang.ts, 24, 21), Decl(narrowingUnionWithBang.ts, 25, 21), Decl(narrowingUnionWithBang.ts, 26, 21) ... and 3 more) |
| 143 | +>borked.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 144 | +>borked : Symbol(borked, Decl(narrowingUnionWithBang.ts, 32, 5)) |
| 145 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 146 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 22, 21), Decl(narrowingUnionWithBang.ts, 23, 21), Decl(narrowingUnionWithBang.ts, 24, 21), Decl(narrowingUnionWithBang.ts, 25, 21), Decl(narrowingUnionWithBang.ts, 26, 21) ... and 3 more) |
| 147 | + |
| 148 | +} else { |
| 149 | + console.log(borked.thing!.id); |
| 150 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 151 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 152 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 153 | +>borked.thing!.id : Symbol(id, Decl(narrowingUnionWithBang.ts, 30, 22)) |
| 154 | +>borked.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 155 | +>borked : Symbol(borked, Decl(narrowingUnionWithBang.ts, 32, 5)) |
| 156 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 20, 19)) |
| 157 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 30, 22)) |
| 158 | +} |
| 159 | + |
| 160 | +export type FixedType = { |
| 161 | +>FixedType : Symbol(FixedType, Decl(narrowingUnionWithBang.ts, 37, 1)) |
| 162 | + |
| 163 | + thing?: |
| 164 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 165 | + |
| 166 | + { name: 'Error1', message: string } | |
| 167 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 41, 5)) |
| 168 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 41, 21)) |
| 169 | + |
| 170 | + { name: 'Error2', message: string } | |
| 171 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 42, 5)) |
| 172 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 42, 21)) |
| 173 | + |
| 174 | + { name: 'Error3', message: string } | |
| 175 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 43, 5)) |
| 176 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 43, 21)) |
| 177 | + |
| 178 | + { name: 'Error4', message: string } | |
| 179 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 44, 5)) |
| 180 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 44, 21)) |
| 181 | + |
| 182 | + { name: 'Error5', message: string } | |
| 183 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 45, 5)) |
| 184 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 45, 21)) |
| 185 | + |
| 186 | + { name: 'Error6', message: string } | |
| 187 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 46, 5)) |
| 188 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 46, 21)) |
| 189 | + |
| 190 | + { name: 'Error7', message: string } | |
| 191 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 47, 5)) |
| 192 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 47, 21)) |
| 193 | + |
| 194 | + { name: 'Error8', message: string } | |
| 195 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 48, 5)) |
| 196 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 48, 21)) |
| 197 | + |
| 198 | + { name: 'Correct', id: string } |
| 199 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 49, 5)) |
| 200 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 49, 22)) |
| 201 | + |
| 202 | +}; |
| 203 | +const fixed: FixedType = null as unknown as FixedType; |
| 204 | +>fixed : Symbol(fixed, Decl(narrowingUnionWithBang.ts, 51, 5)) |
| 205 | +>FixedType : Symbol(FixedType, Decl(narrowingUnionWithBang.ts, 37, 1)) |
| 206 | +>FixedType : Symbol(FixedType, Decl(narrowingUnionWithBang.ts, 37, 1)) |
| 207 | + |
| 208 | +if (fixed.thing?.name !== "Correct") { |
| 209 | +>fixed.thing?.name : Symbol(name, Decl(narrowingUnionWithBang.ts, 41, 5), Decl(narrowingUnionWithBang.ts, 42, 5), Decl(narrowingUnionWithBang.ts, 43, 5), Decl(narrowingUnionWithBang.ts, 44, 5), Decl(narrowingUnionWithBang.ts, 45, 5) ... and 4 more) |
| 210 | +>fixed.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 211 | +>fixed : Symbol(fixed, Decl(narrowingUnionWithBang.ts, 51, 5)) |
| 212 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 213 | +>name : Symbol(name, Decl(narrowingUnionWithBang.ts, 41, 5), Decl(narrowingUnionWithBang.ts, 42, 5), Decl(narrowingUnionWithBang.ts, 43, 5), Decl(narrowingUnionWithBang.ts, 44, 5), Decl(narrowingUnionWithBang.ts, 45, 5) ... and 4 more) |
| 214 | + |
| 215 | + console.log(fixed.thing!.message); |
| 216 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 217 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 218 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 219 | +>fixed.thing!.message : Symbol(message, Decl(narrowingUnionWithBang.ts, 41, 21), Decl(narrowingUnionWithBang.ts, 42, 21), Decl(narrowingUnionWithBang.ts, 43, 21), Decl(narrowingUnionWithBang.ts, 44, 21), Decl(narrowingUnionWithBang.ts, 45, 21) ... and 3 more) |
| 220 | +>fixed.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 221 | +>fixed : Symbol(fixed, Decl(narrowingUnionWithBang.ts, 51, 5)) |
| 222 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 223 | +>message : Symbol(message, Decl(narrowingUnionWithBang.ts, 41, 21), Decl(narrowingUnionWithBang.ts, 42, 21), Decl(narrowingUnionWithBang.ts, 43, 21), Decl(narrowingUnionWithBang.ts, 44, 21), Decl(narrowingUnionWithBang.ts, 45, 21) ... and 3 more) |
| 224 | + |
| 225 | +} else { |
| 226 | + console.log(fixed.thing.id); |
| 227 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 228 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 229 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 230 | +>fixed.thing.id : Symbol(id, Decl(narrowingUnionWithBang.ts, 49, 22)) |
| 231 | +>fixed.thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 232 | +>fixed : Symbol(fixed, Decl(narrowingUnionWithBang.ts, 51, 5)) |
| 233 | +>thing : Symbol(thing, Decl(narrowingUnionWithBang.ts, 39, 25)) |
| 234 | +>id : Symbol(id, Decl(narrowingUnionWithBang.ts, 49, 22)) |
| 235 | +} |
0 commit comments