Files
scriptc/tests/corpus/2789-array-missing-optional-tostring.ts
Chris Tate 94fd361b54 Implement sparse native arrays and missing-value parity (#297)
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
2026-09-12 22:39:07 -05:00

18 lines
677 B
TypeScript

// Optional-call and optional-receiver chains keep their undefined tail while
// checker-proven guards expose the present string to later builtin calls.
type Probe = { get?: () => number };
function probe(present: boolean): Probe {
return present ? { get: () => 42.5 } : {};
}
const hit = probe(true).get?.()?.toString();
const miss = probe(false).get?.()?.toString();
console.log(hit, miss);
console.log(hit !== undefined && /^42/.test(hit));
console.log(miss !== undefined && /^42/.test(miss));
function maybeNumber(present: boolean): number | undefined {
return present ? 1e21 : undefined;
}
console.log(maybeNumber(true)?.toString(), maybeNumber(false)?.toString());