You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
The funding will be given to active contributors.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
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 detectInfinity
and-Infinity
so I still have some hope. :)The affected helpers are
Jsonify
andFinite
, while this list may not be exhaustive.In case of
Jsonify
, aNaN
value is encoded asnull
anumber
can be incorrectly encoded asnumber
when it's aNaN
.In case of
Finite
, sinceNaN
is not included in finite numbers (according toNumber.isFinite
check), it can also return an incorrect type in case ofNaN
.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.
Upvote & Fund
The text was updated successfully, but these errors were encountered: