mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
45 lines
986 B
TypeScript
45 lines
986 B
TypeScript
//// [tests/cases/compiler/controlFlowDestructuringLoop.ts] ////
|
|
|
|
//// [controlFlowDestructuringLoop.ts]
|
|
// 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
//// [controlFlowDestructuringLoop.js]
|
|
"use strict";
|
|
// Repro from #28758
|
|
function isNumVal(x) {
|
|
return typeof x.val === 'number';
|
|
}
|
|
function foo(things) {
|
|
for (const thing of things) {
|
|
if (isNumVal(thing)) {
|
|
const { val } = thing;
|
|
val.toFixed(2);
|
|
}
|
|
else {
|
|
const { val } = thing;
|
|
val.length;
|
|
}
|
|
}
|
|
}
|