TypeScript/tests/cases/compiler/controlFlowDestructuringLoop.ts
2018-11-30 16:28:21 -08:00

24 lines
484 B
TypeScript

// @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;
}
}
}