From 290eff9722a2f8a0f267c30a3b3e78a16489b985 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 30 Nov 2018 16:28:21 -0800 Subject: [PATCH] Add regression test --- .../compiler/controlFlowDestructuringLoop.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/cases/compiler/controlFlowDestructuringLoop.ts diff --git a/tests/cases/compiler/controlFlowDestructuringLoop.ts b/tests/cases/compiler/controlFlowDestructuringLoop.ts new file mode 100644 index 0000000000..bf3a68cb2d --- /dev/null +++ b/tests/cases/compiler/controlFlowDestructuringLoop.ts @@ -0,0 +1,24 @@ +// @strict: true + +// Repro from #28758 + +interface NumVal { val: number; } +interface StrVal { val: string; } +type Val = NumVal | StrVal; + +function isNumVal(x: Val): x is NumVal { + return typeof x.val === 'number'; +} + +function foo(things: Val[]): void { + for (const thing of things) { + if (isNumVal(thing)) { + const { val } = thing; + val.toFixed(2); + } + else { + const { val } = thing; + val.length; + } + } +} \ No newline at end of file