-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use JsonValue
as JSON.parse
Return Type?
#10
Comments
I think |
This comment was marked as off-topic.
This comment was marked as off-topic.
@j if the aim is type safety, that isn't safe |
@j Hiding this as not relevant to the issue. Please also take a look at the readme, where I mention in detail the reason why we won't be implementing this. |
true; understood. I live in a world where I consume self-owned APIs and messages that are type-safe at the point of having to parse it, so my brain went there. with that said, leaving as |
Same applies to |
I'd like to see JsonValue when no reviver too. I can't see how it's less safe? |
OK - I think I prefer unknown here instead of |
I created a PR, #123, for a type-safe and sound version of |
@mattpocock Consider the following playground example. With |
Perhaps this would go further that what is wanted from this library, but I think it'd be nice if
JSON.parse
could return a type similar to (or the same as)JsonValue
fromtype-fest
(see https://github.com/sindresorhus/type-fest#json).I've never used the optional
reviver
function inJSON.parse
, but it looks like it can modify the return type beyondJsonValue
, so perhaps it'd make sense to have a return type ofJsonValue
if noreviver
is passed, thenunknown
if areviver
is passed?The text was updated successfully, but these errors were encountered: