Description
Hi, I just found out about this project while writing my own Jsonify
helper.
I wanted to document a few limitations regarding the unfortunate situation with NaN
. Maybe this can be added to the readme.
Unfortunately, NaN
is not a TypeScript literal and cannot be detected at the type-level. I'm surprised that you found a way to detect Infinity
and -Infinity
so I still have some hope. :)
The affected helpers are Jsonify
and Finite
, while this list may not be exhaustive.
In case of Jsonify
, a NaN
value is encoded as null
a number
can be incorrectly encoded as number
when it's a NaN
.
In case of Finite
, since NaN
is not included in finite numbers (according to Number.isFinite
check), it can also return an incorrect type in case of NaN
.
For context, I needed a Jsonify
utility to have typed loader data in Remix, after a JSON encode/decode chain. I also opened an issue (microsoft/TypeScript#48697) in TypeScript repo to request a first-class helper type.
I hope this issue will be helpful and I can try to help in any way I can.