Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN problems #406

Open
frontsideair opened this issue Jun 25, 2022 · 0 comments
Open

NaN problems #406

frontsideair opened this issue Jun 25, 2022 · 0 comments

Comments

@frontsideair
Copy link
Contributor

frontsideair commented Jun 25, 2022

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.

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.
Fund with Polar
This was referenced Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants