Service binding type
What is the correct type for a service binding (worker to worker)? I have currently typed as
Fetcher
but I'm getting an error trying to provide a body to the request:
This gives me an error on body
: Type 'FormData' is not assignable to type 'BodyInit | null | undefined'
so I assume I'm typing the binding incorrectly as RequestInit
should accept FormData
based on the docs for Fetch
.
The docs suggest that Fetcher is the correct type, but as above that doesn't seem right? https://developers.cloudflare.com/workers/runtime-apis/service-bindingsService bindings · Cloudflare Workers docs
Service bindings are an API that facilitate Worker-to-Worker communication via explicit bindings defined in your configuration. A Service binding …
3 Replies
This appears to be an issue with fetch and FormData types https://github.com/form-data/form-data/issues/513
Ahh, thanks - I wasn't aware of that issue. Is there any workaround other than
as any
?I did find a StackOverflow answer that suggested I just need to stringify the body:
This now works.
https://stackoverflow.com/questions/43997163/how-to-make-request-body-type-compatible-with-requestinit-or-bodyinit-when-using
Stack Overflow
How to make request body type compatible with RequestInit or BodyIn...
I started to use Typescript for my nodejs project. For accessing some external API, I use node-fetch to make requests. While setting up a PUT request, an error pops up, saying that the given body i...