#ReadableStream type error

5 messages · Page 1 of 1 (latest)

primal atlas
#

Not sure what I'm doing wrong here, but I'm getting a type error when trying to pass a request body on unchanged in a fetch.

Worker code is as follows:

export default {
  async fetch(req: WorkerRequest, _env: unknown, _ctx: WorkerExecutionContext) {
    const init: RequestInit = {
      body: req.body,
      headers: {
        "User-Agent": req.headers.get("User-Agent")!,
      },
      method: 'POST',
    }

    let path = new URL(req.url).pathname
    let address = 'https://pythondiscord.report-uri.com' + path
    let response = await fetch(address, init);

    return new Response(response.body, {
      status: response.status,
      statusText: response.statusText
    })
  }
}

It doesn't like the req.body being passed into the body of the RequestInit for whatever reason

#

Error seems weird because I would've assumed ReadableStream<Uint8Array> would fit within ReadableStream<any>?

#

body must be of type BodyInit

#

which then itself is Uint8Array?

#

or it might be the other way round, i'm not familiar with typescript errors, but either way, i'm not sure how to constrain the body to that desired type