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