Files
scriptc/tests/diagnostics/union-clone-override-width.ts
Chris Tate 3af05d9fbc feat(compiler): lower the complete frontend statically
- Complete frontend lowering with zero rejected statements, dynamic islands, or skipped functions.
- Support contextual construction, presence guards, and union record copies used by the compiler.
- Add native CommonJS resolution and cross-platform file URL handling while preserving Node host behavior.
2026-09-28 23:49:13 -05:00

12 lines
738 B
TypeScript

type Payload = { tag: "number"; value: number } | { tag: "text"; value: string };
type WiderPayload = { tag: "number"; value: number; extra: boolean } | { tag: "text"; value: string; extra: boolean };
type Container = { kind: "left"; payload: Payload; left: number } | { kind: "right"; payload: Payload; right: number };
function copy(source: Container, payload: WiderPayload): boolean {
// Retagging the override into source.payload would discard extra and
// copy its record. The inferred spread result keeps the wider payload.
const result = { ...source, payload };
return result.payload.extra;
}
console.log(copy({ kind: "left", payload: { tag: "number", value: 1 }, left: 2 }, { tag: "text", value: "kept", extra: true }));