The official TypeScript lib type definition for the value
argument to JSON.stringify(value)
is any
.
Is there a stricter type for value
such that serializing and deserializing it would result the same value? In other words, such that the following were true:
deepEqual(value, JSON.parse(JSON.stringify(value)))
For example, if value
were a Date
object, the above statement would be false.
The answer I’m looking for is
type SerializableValue = ...
2
Answers
Adding to Dimava's answer and this GitHub issue,
type JSONValue
is the closest it gets:But, there are still some limitations:
Technically there are more things JSON can serialize, but the above is what it can deseriaize
You may use
in a
my-global-types.d.ts
in your project to declare it globally