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?
Cloudflare Docs
Response | Cloudflare Workers docs
Interface that represents an HTTP response.
7 Replies
Hard@Work
Hard@Work4mo ago
Assuming that the global.Response type is coming from Node, I would use
declare module "@types/node" {
declare const value: unknown;
export default value;
}
declare module "@types/node" {
declare const value: unknown;
export default value;
}
to get rid of it
Honumael (MasterQuestMaster)
Thanks, where would I put this?
Hard@Work
Hard@Work4mo ago
I usually put it in a .d.ts file in my types directory, which I include in typechecking with this in my tsconfig.json:
{
// ...
"include": ["src", "types"]
}
{
// ...
"include": ["src", "types"]
}
Honumael (MasterQuestMaster)
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.
Hard@Work
Hard@Work4mo ago
If you try to find the source of the Response type, where is it coming from?
Honumael (MasterQuestMaster)
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!
Hard@Work
Hard@Work4mo ago
Yeah, the typechecker works in mysterious ways...
Want results from more Discord servers?
Add your server