TypeScript error with global Response object
Hello!
So I'm trying to build a Worker with TypeScript. I'm using the regular node-internal "fetch" which seems to return a "global.Response". When I try to make a function that takes that Response as parameter of type "Response", TS complains that
Argument of type 'global.Response' is not assignable to parameter of type 'Response'.
Type 'Response' is missing the following properties from type 'Response': webSocket, cf, bytes
It seems there's a conflict between the Workers "Response" (https://developers.cloudflare.com/workers/runtime-apis/response/) and the integrated Response type. I cannot seem to use "global.Response" as an argument type, so does anyone know how to handle this conflict?7 Replies
Assuming that the
global.Response
type is coming from Node, I would use to get rid of itThanks, where would I put this?
I usually put it in a
.d.ts
file in my types
directory, which I include in typechecking with this in my tsconfig.json
: I tried to put it adjust my tsconfig to include "types" and put your code into "types/node.d.ts", but the error persists.
The global.Response is what I get back when I:
const response = await fetch("https://url")
so it should be from node though.If you try to find the source of the Response type, where is it coming from?
wait a sec... it just started working with your solution. It seems it took a while to register the changes (even though I also restarted VS Code thinking that would update it). Thanks a lot for your help!
Yeah, the typechecker works in mysterious ways...