Implement support for serializing Headers, Request, and Response.#135
Implement support for serializing Headers, Request, and Response.#135
Conversation
There are some ugly hacks to work around Firefox not supporting `request.body`. Ugh. (I started out asking Claude to do this but it actually failed in a bunch of ways and I ended up rewriting most of it.)
|
commit: |
| // `as Uint8Array` is needed here to work around some sort of weird bug in the TS | ||
| // types where `new Uint8Array` somehow doesn't return a `Uint8Array`. Instead it | ||
| // somehow returns `Uint8Array<ArrayBuffer>` -- but `Uint8Array` is not a generic | ||
| // type! WTF? |
There was a problem hiding this comment.
fwiw, re: this
I think it's because there's a variable and a type with the same name (unfortunate thing that's happened a few times, some worse than others (apocalypse coming if the Record global proposal ever lands and overlaps with the utility type name)).
There's the declare var called Uint8Array which has the constructor type defined here. There's a few overloads for the newable type definition, but they all return a type of the same name Uint8Array defined here which is generic (you can also get to it from globalThis.Uint8Array<...>).
similar to working with class types (which, this time by design have the same name as their types) when you use Uint8Array as a type (with an as casting, for example here) then it's disambiguated.
at least, that's how I understand it.
What error do you see when you remove the cast? I pulled down this branch and removed it and didn't see an error right away.
There was a problem hiding this comment.
npx tsc --noEmit says:
src/serialize.ts:222:36 - error TS2769: No overload matches this call.
Overload 1 of 2, '(chunk?: Uint8Array | undefined): void', gave the following error.
Type 'Uint8Array<ArrayBuffer>' has no properties in common with type 'Uint8Array'.
Overload 2 of 2, '(chunk?: Uint8Array | undefined): void', gave the following error.
Type 'Uint8Array<ArrayBuffer>' has no properties in common with type 'Uint8Array'.
222 controller.enqueue(new Uint8Array(await bodyPromise));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are some ugly hacks to work around Firefox not supporting
request.body. Ugh.(I started out asking Claude to do this but it actually failed in a bunch of ways and I ended up rewriting most of it.)