Files
scriptc/tests/corpus/bigint-checked-casts.ts
Chris Tate 97a489845a Preserve native values through renderer initialization
- Carry BigInts, Sets, and regular expressions through checked native storage without a JavaScript engine.
- Preserve dictionary aliases, spreads, frozen metadata, and fluent initialization helpers.
- Collect checked object and closure cycles while preserving live references.
2026-09-29 00:20:53 -05:00

17 lines
853 B
TypeScript

import assert from "node:assert/strict";
function opaque(value: unknown): unknown { return value; }
const value = opaque({ pointer: 18446744073709551615n, nested: [-1n, 0n] });
const typed = value as { pointer: bigint; nested: bigint[] };
console.log(typed.pointer.toString(16), typed.nested[0] === -1n);
const maybe = opaque(0n) as bigint | undefined;
console.log(maybe === 0n);
const boxed = opaque(18446744073709551615n);
if (typeof boxed === "bigint") console.log(boxed + 1n);
assert.strictEqual(boxed, opaque(18446744073709551615n));
assert.deepStrictEqual(value, opaque({ pointer: 18446744073709551615n, nested: [-1n, 0n] }));
try { console.log((opaque(1) as bigint) + 1n); }
catch (error) { if (error instanceof Error) console.log(error.name); }
console.log("checked");
console.log((18446744073709551615n as unknown) === 18446744073709551615n);