Skip to content

Conversation

@ysangkok
Copy link

@ysangkok ysangkok commented Nov 27, 2025

Description of the change
This makes the underlying Json type polymorphic. You can now plug in a type
to use for numbers, and you can then avoid losing precision when handling JSON
with the Number. I am working on a library for infinite precision numbers in
scientific notation, which I can show if there is interest. One could also use decimals.

Existing users remain compatible with this change since Json is still
available as a type synonym for Json Number. You only get new functionality
if you import the new module.

Note that this feature depends on a new JavaScript runtime:

In the new API, stringify can fail, which happens for example when you emit
invalid JSON or run the code on an old JavaScript runtime. I have tested
manually that it fails gracefully on Node.js v20. But this test isn't included
in the automated test suite, since I am not sure if the test suite should be
doing feature probing. It would be hard to know whether the feature is
'supposed' to work.

Pinging @thomashoneyman and @garyb as I was told on Discord that they might be
interested.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant