hunt
CDCloudflare Developers
•Created by herenickname on 2/19/2025 in #workers-help
How to create a binding TS types from RPC worker?
ofc!
6 replies
CDCloudflare Developers
•Created by hunt on 2/19/2025 in #workers-help
Returning an RpcTarget from a WorkerEntrypoint shows `never` for method return types
Maybe complex types is a bad way to describe what i'm returning -- the issue i'm running into is if the object i'm returning is anything but a simple value like a
string
or a number
(like any key-value object { foo: "bar" }
) then it isn't serializable.7 replies
CDCloudflare Developers
•Created by hunt on 2/19/2025 in #workers-help
Returning an RpcTarget from a WorkerEntrypoint shows `never` for method return types
oh interesting. I would've assumed that stub types would take on a different form for the reserved methods like fetch, as in it skips using RPC entirely since the signature of stub.fetch and DurableObject.fetch isn't one to one (there's some transformations in between that cloudflare takes). Regardless it's still an issue if you return a response object from a non-fetch RPC method
https://developers.cloudflare.com/durable-objects/api/base/
7 replies
CDCloudflare Developers
•Created by herenickname on 2/19/2025 in #workers-help
How to create a binding TS types from RPC worker?
AFAIK not in the way you're describing. you still need to expose some way to access those stubs through an entrypoint on the parent worker of your objects. (i.e. you can't create a binding to a durable object that lives on another worker)
I have a similar want to what you're describing, and something like this is as close as I've come to what I'm hoping for.
/DOs/src/index.ts
/api/src/index.ts
There's some issues regarding types when using rpc in this fashion (and maybe some inefficiencies, I'm still trying to corner that myself).
https://discord.com/channels/595317990191398933/1341606596186341519
6 replies
CDCloudflare Developers
•Created by herenickname on 2/19/2025 in #workers-help
How to create a binding TS types from RPC worker?
I haven't seen a way to do that in a typegen fashion, but it can be solved by making a edit to the env object in the referencing worker
https://github.com/hntrl/durable-object-rpc-repro/blob/9804eccb6468db2d0363ca86aa1f1e96e63f7c63/packages/workerB/worker-configuration.d.ts#L4
(setting the type parameter of the Fetcher to the class of whatever it is you're trying to access)
6 replies