Correct TypeScript from WorkerEntrypoint Binding
If I have this service below
When I consume this into another service provider it has in its toml
When I run
wrangler types
it generaties this type decleration file
However when I try to use this service it only shows two methods which are the reserved types connect
and fetch

9 Replies
There's a separate type for RPC services,
Service<Users>
in this case, if you import type Users from './other.ts'
The way I usually have them would be USERS: Service<import('other-service').default>
as inline type importsOh intersting thanks @DaniFoldi !
Maybe this deserves its own question, but it is something I am struggling with when getting started to write out my next course on creating cloudflare workers.
I am wondering if it makes sense to continue with multiple wrangler directories for each service like in
flipfeeds
currently or do something like @Craig has in punderful-workflows
creating multiple services in a single wrangler directory.
I feel like this is where they typing might also break down because technically they are not even in the same project making imports more difficult

I would do it in a very similar way to your setup
- pnpm monorepo, each worker is a package
- make the exported worker's type an export of the package
- import them from
workspace:^
in other packages - and this should work in the same repo as well as others, if you publish it to a (maybe private) registryHow do you test things like this locally, I am finding it difficult to run workers concurrently with only my gateway being served at
8787
. I "hardcoded" port into its pnpm dev command but maybe there is another way?I believe the
port
config option in wrangler.toml/json is what you're looking for, I'd assign them something unique each
(insert obligatory testing in production joke)
and then an actual explanation, you can use gradual deployments, eg. upload your new version and deploy it to 0% of traffic, which you can override with a header for your own requestsSorry for interrupting this thread with my own question but im running into same issue and I'm unable to fix it. Could you explain me a bit further how do I accomplish the type of RPC service to be
Service<...>
instead of type Fetcher
when worker-configuration.d.ts is generated ? Thanks a lotHey, unfortunately the only solution I can give is to manually overwrite it :/
sadly generics are not supported by the type generator right now, even though it would be super useful, and also something I've asked about in the past
Ye Unfortunately I found out the the hard way and monorepo did its own part in escalating the difficulty but finally after 2 days of typescript hell I got it working in acceptable manners 😄
Try something like this:
(Where that Uploader is the exported class name at that relative dir)