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.
I like seeing the addition of types and type checks by the library itself!
Given that the input can be a non-object and
JSON.stringify
can also have a non object input, the typings should reflect that. Especially as json-stable-stringify can be more of a drop-in replacement ofJSON.stringify
then. (I noticed this as updating this library resulted in type errors for me as my input could be a string in some cases)Both
JSON.stringify
and@types/json-stable-stringify
useany
for this. Which is ok for providing typings for external code but worse for type checking the actual code with typescript.any
allows doing all kinds of stuff, TypeScript just assumes that its probably ok, whileunknown
requires you to check the types before using them (which is done by this library). So TypeScript ensures the type checks are correct.I also added tests that ensure that non-object input actually works both in JavaScript and have working typings (without the change to
unknown
TypeScript is unhappy). Not sure whether they are in the correct file. Should they get their own test file?