Files
scriptc/tests/diagnostics/inferred-callback-drops-conditional.ts
T
2026-10-20 17:56:44 -05:00

13 lines
467 B
TypeScript

type Plain = { name: string; n: number };
type Item = Plain & { extra?: boolean };
const plain: Plain[] = [{ name: "a", n: 1 }];
function run<T>(fn: () => T): T {
return fn();
}
// The checker unifies both branches into Plain[]; the extended objects keep
// `extra` in Node, so converting them into Plain would drop it silently.
const items: Item[] = run(() =>
plain.length === 0 ? plain : plain.map((x) => ({ ...x, extra: true })),
);
console.log(items.length);