Features
Add a __.NaN
pattern, matching only NaN
s values. Thanks @mhintz for adding this
const res = match<number | null>(NaN)
.with(null, () => 'null!')
.with(__.NaN, () => 'NaN!')
.with(__.number, (x) => 'a number!')
.exhaustive();
console.log(res)
// => 'NaN!'
Bugfix
Update the __.number
pattern to also match on NaN
values.
Since NaN
has type number
in TypeScript, there is no way to distinguish a NaN
from a regular number at the type level. This was causing an issue where .exhaustive()
considered all numbers handled by the __.number
pattern even though NaN
wasn't matched by it, resulting in possible runtime errors.
const res = match<number | null>(NaN)
.with(null, () => 'null!')
.with(__.number, (x) => 'a number!')
// This used to throw at runtime because NaN wasn't matched by __.number
.exhaustive();
console.log(res)
// => 'a number!'