Change the type of json
from JSONValue
to unknown
#371
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.
BREAKING CHANGES IN THE TYPE DEFINITIONS
The
JSONValue
type is too limited, for example when using thelossless-json
parser instead ofJSON
, there can be instances ofLosslessNumber
. Other parsers may generatedBigInt
instances, etc. Therefore, definingjson
asunknown
is more "accurate".So the following (core) type definitions:
Will now become:
Also, the type of
JSONParser
is changed fromtype JSONParser = JSON
to an explicit description, which has one difference withJSON.stringify
namely that it can returnstring | undefined
instead ofstring
. The current official type definition ofJSON
is lacking in this regard:JSON.stringify(undefined)
returnsundefined
, but this is not reflected in the type, which can lead to a false sense of null-safety. See: https://stackoverflow.com/questions/74461780/is-the-official-type-definition-for-json-stringify-wrong.All in all, this should result in a more smooth TypeScript experience and less need for type casting.