mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
- lowerUnitComparison folds ===/!== against a union lacking the unit arm to the constant answer, both operand orders - a non-droppable operand still evaluates exactly once, riding a throwaway tag test - union-switch case null / case undefined take the unit-comparison lowering, so a lacking arm never matches - the unionEq fallback had coerced the literal through the stranded-arm trap, throwing where Node answers false - corpus 2490-2494: the find-miss repro, every strict and loose spelling, switch unit cases, effect preservation
11 lines
567 B
TypeScript
11 lines
567 B
TypeScript
// The find-miss regression, verbatim: `.find` misses give `number | undefined`, and comparing that against the null LITERAL is legal TS that is simply always false — the literal must never coerce into the union representation (the stranded-arm trap threw here while console widening had just made the program compile).
|
|
const xs = [1, 2, 3];
|
|
const hit = xs.find((x) => x > 2);
|
|
const miss = xs.find((x) => x > 10);
|
|
console.log(hit);
|
|
console.log(miss);
|
|
console.log(miss === undefined);
|
|
console.log(miss === null);
|
|
console.log(miss ?? -1);
|
|
console.log(xs.indexOf(9));
|