-
Notifications
You must be signed in to change notification settings - Fork 570
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
improve HeadersInit
type
#2373
improve HeadersInit
type
#2373
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2373 +/- ##
==========================================
+ Coverage 85.54% 85.84% +0.29%
==========================================
Files 76 76
Lines 6858 6886 +28
==========================================
+ Hits 5867 5911 +44
+ Misses 991 975 -16
☔ View full report in Codecov by Sentry. |
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.
Technically webidl will handle any type we pass (null
, numbers, objects, arrays, etc.) but we should be explicit in what types/values are expected (being what the spec tells us). Typescript's own DOM types do as much https://github.com/microsoft/TypeScript/blob/11a04ed9086e1e89cab970901b3496d5a67bcf59/src/lib/dom.generated.d.ts#L27983
IMO the ReadonlyArray should be removed because it's not an expected value, I'm really not sure how that ended up there. Webidl will handle it, but probably not in an expected way, and we probably shouldn't encourage people to misuse it. |
I hear ya but we should match browser behavior. And honestly our types should match our implementation. If the spec does say to fail on undefined, and if our implementation doesn't fail on it either, I see little harm in adjusting the types so that we can avoid an unnecessary |
If you pass |
…r.mts` (#10767) In a recent undici update, setting the `host` header for fetch requests became invalid (nodejs/undici#2322). We relied on this in order to proxy serverless dev server requests via `@vercel/node`. This PR replaces the usage of `undici.fetch` with `undici.request`. It is blocked by an `undici` type change: nodejs/undici#2373
Closing due too inactivity. |
This PR improves the
HeadersInit
type. The spec sorta gets this wrong (https://fetch.spec.whatwg.org/#typedefdef-headersinit) It only specifiesrecord<ByteString, ByteString>
, butrecord<ByteString, ByteString | undefined
also works. I've tested it in multiple browsers and our implementation, and it works fine.This allows me to pass an
IncomingHTTPHeaders
object directly to the constructor (which is valid for all other reasons except for this missing| undefined
).