The JSONValue type is too limited, for example when using the lossless-json parser instead of JSON, there can be instances of LosslessNumber. Other parsers may generated BigInt instances, etc. Therefore, defining json as unknown is more "accurate".
export type TextContent = { text: string }
export type JSONContent = { json: unknown }
export type Content = JSONContent | TextContent
Also, the type of JSONParser is changed from type JSONParser = JSON to an explicit description, which has one difference with JSON.stringify namely that it can return string | undefined instead of string. The current official type definition of JSON is lacking in this regard: JSON.stringify(undefined) returns undefined, 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.
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.