ReadableStream type error

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
})
}
}
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
No description
4 Replies
joe
joeOP16mo ago
Error seems weird because I would've assumed ReadableStream<Uint8Array> would fit within ReadableStream<any>?
joe
joeOP16mo ago
body must be of type BodyInit
No description
joe
joeOP16mo ago
which then itself is Uint8Array?
No description
joe
joeOP16mo ago
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 looks like it was something in my tsconfig, copying the latest one from the template works
Want results from more Discord servers?
Add your server