|
| 1 | +=== tests/cases/compiler/controlFlowDestructuringLoop.ts === |
| 2 | +// Repro from #28758 |
| 3 | + |
| 4 | +interface NumVal { val: number; } |
| 5 | +>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0)) |
| 6 | +>val : Symbol(NumVal.val, Decl(controlFlowDestructuringLoop.ts, 2, 18)) |
| 7 | + |
| 8 | +interface StrVal { val: string; } |
| 9 | +>StrVal : Symbol(StrVal, Decl(controlFlowDestructuringLoop.ts, 2, 33)) |
| 10 | +>val : Symbol(StrVal.val, Decl(controlFlowDestructuringLoop.ts, 3, 18)) |
| 11 | + |
| 12 | +type Val = NumVal | StrVal; |
| 13 | +>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33)) |
| 14 | +>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0)) |
| 15 | +>StrVal : Symbol(StrVal, Decl(controlFlowDestructuringLoop.ts, 2, 33)) |
| 16 | + |
| 17 | +function isNumVal(x: Val): x is NumVal { |
| 18 | +>isNumVal : Symbol(isNumVal, Decl(controlFlowDestructuringLoop.ts, 4, 27)) |
| 19 | +>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18)) |
| 20 | +>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33)) |
| 21 | +>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18)) |
| 22 | +>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0)) |
| 23 | + |
| 24 | + return typeof x.val === 'number'; |
| 25 | +>x.val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 2, 18), Decl(controlFlowDestructuringLoop.ts, 3, 18)) |
| 26 | +>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18)) |
| 27 | +>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 2, 18), Decl(controlFlowDestructuringLoop.ts, 3, 18)) |
| 28 | +} |
| 29 | + |
| 30 | +function foo(things: Val[]): void { |
| 31 | +>foo : Symbol(foo, Decl(controlFlowDestructuringLoop.ts, 8, 1)) |
| 32 | +>things : Symbol(things, Decl(controlFlowDestructuringLoop.ts, 10, 13)) |
| 33 | +>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33)) |
| 34 | + |
| 35 | + for (const thing of things) { |
| 36 | +>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14)) |
| 37 | +>things : Symbol(things, Decl(controlFlowDestructuringLoop.ts, 10, 13)) |
| 38 | + |
| 39 | + if (isNumVal(thing)) { |
| 40 | +>isNumVal : Symbol(isNumVal, Decl(controlFlowDestructuringLoop.ts, 4, 27)) |
| 41 | +>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14)) |
| 42 | + |
| 43 | + const { val } = thing; |
| 44 | +>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 13, 19)) |
| 45 | +>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14)) |
| 46 | + |
| 47 | + val.toFixed(2); |
| 48 | +>val.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) |
| 49 | +>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 13, 19)) |
| 50 | +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) |
| 51 | + } |
| 52 | + else { |
| 53 | + const { val } = thing; |
| 54 | +>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 17, 19)) |
| 55 | +>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14)) |
| 56 | + |
| 57 | + val.length; |
| 58 | +>val.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) |
| 59 | +>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 17, 19)) |
| 60 | +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments