Files
scriptc/tests/corpus/2490-find-miss-null-compare.ts
Chris Tate 8d2b3bb2e0 No-arm unit comparisons answer constants instead of trapping
- 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
2026-07-23 14:34:41 -05:00

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));