-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
fix: narrow body
type for HttpResponse.json()
to be serializable json
#1838
Conversation
ReadableStream
body to HttpResponse.json()
ReadableStream
body to HttpResponse.json()
ReadableStream
body to HttpResponse.json()
body
type for HttpResponse.json()
to be serializable json
body
type for HttpResponse.json()
to be serializable jsonbody
type for HttpResponse.json()
to be serializable json
@@ -19,6 +19,14 @@ export type DefaultBodyType = | |||
| null | |||
| undefined | |||
|
|||
export type JsonBodyType = | |||
| Record<string, any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do we want to be slightly more prescriptive than Record<string, any>
here, Record<string, JsonBodyType>
might be the most correct option?
also I think we'd need to account for Array<JsonBodyType>
too? (and potentially their readonly varieties?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly, TypeScript is permissive about this and arrays extend Record<string, any>
quite well. It's the any
part that does the trick.
As to narrowing down the type from any
to a recursive JsonBodyType
, I'm not so sure about it. It sounds like the right thing to do but there's always corner cases people run into, and it's hard to predict what will happen if we make this body type that strict.
Released: v2.0.4 🎉This has been released in v2.0.4! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Changes
body
type of theHttpResponse.json()
static method must be a serializable JSON. Narrow the argument type to reflect that.JsonBodyType
type from the core.