Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the ability for
fast-json-stringify
to coerce Dates into strings and BigInts into numbers. These type tests weren't having any effect before: when schemas are declared likeschema1
andschema2
are typed simplySchema
, so none of the nice type inference is triggered and you can pass any argument to the method, likeAnd there will be no type error. This adds some duplication because the two options that I know of are either adding
as const
to the end of each schema declaraction, or using a literal.as const
doesn't work in this situation because it makes the type readonly, which then isn't accepted bybuild()
.This disables a bunch of tests here: https://github.com/fastify/fast-json-stringify/pull/683/files#diff-72016aeffe80c3b259bbbf7e92a664cd2bcf49c2b79597740b4dcd8e430107bdR161 which are breaking for a different reason - the type declaration itself has always, afaict, been wrong, and there isn't an easy way to fix it. This PR just uncovered that pre-existing issue.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct