Skip to content

wrangler types for service bindings missing rpc methods #8902

@nickfujita

Description

@nickfujita

Which Cloudflare product(s) does this pertain to?

Wrangler

What versions & operating system are you using?

Wrangler 4.10.0, @cloudflare/vite-plugin 1.0.5

Please provide a link to a minimal reproduction

No response

Describe the Bug

When binding a service to call via RPC, the methods on the service worker are not available when running wrangler types. It just provides a generic typing Fetcher with the methods fetch and connect. I know @cloudflare/vite-plugin has the auxiliaryWorkers reference to the service worker wrangler.jsonc file, but guessing it's not at all related to how wrangler types works. Is there any way to provide a reference in my wrangler.jsonc to the service worker files so it can correctly pull in the types for the RPC methods on the service worker?

Service worker - worker-b

wrangler.jsonc

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "worker-b",
  "main": "src/index.ts",
  "compatibility_date": "2025-04-11",
}

src/index.tsx

import { WorkerEntrypoint } from 'cloudflare:workers';

export default class extends WorkerEntrypoint<Env> {

  async fetch() {
    return new Response('up');
  }

  async sayHello(greeting: string) {
    return `hello, ${greeting}`;
  }
}

Main worker - worker-a

wrangler.jsonc

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "name": "worker-a",
  "main": "src/index.ts",
  "compatibility_date": "2025-04-11",
  "services": [
    {
      "binding": "WORKER_B",
      "service": "worker-b"
    }
  ]
}

vite.config.ts

import { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";

export default defineConfig({
  plugins: [cloudflare({
    auxiliaryWorkers: [
      {
        configPath: '../worker-b/wrangler.jsonc'
      }
    ]
  })]
});

src/index.ts

export default {
  async fetch(request, env) {
    const result = await env.WORKER_B.sayHello('friend');
    return new Response(result);
  }
}

Expected

  • in worker-a/src/index.ts, the typing for env.WORKER_B.sayHello should be available after running wrangler types

Actual

  • the following type error is given
Property 'sayHello' does not exist on type '{ fetch(input: URL | RequestInfo, init?: RequestInit<CfProperties<unknown>> | undefined): Promise<Response>; connect(address: string | SocketAddress, options?: SocketOptions | undefined): Socket; }'.ts(2339)
  • looking in the generated worker-configuration.d.ts file shows the following typings
declare namespace Cloudflare {
	interface Env {
		WORKER_B: Fetcher;
	}
}
type Fetcher<T extends Rpc.EntrypointBranded | undefined = undefined, Reserved extends string = never> = (T extends Rpc.EntrypointBranded ? Rpc.Provider<T, Reserved | "fetch" | "connect"> : unknown) & {
    fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
    connect(address: SocketAddress | string, options?: SocketOptions): Socket;
};

Work around

  • I could go in and update the WORKER_B type to extend Fetcher with the sayHello RPC method on WORKER_B but since this is a generated file, it just seems fragile. For example, what if a coworker regenerates the file by running wrangler types again and didn't know or forgets to add the extended type again.

Is there some other recommended way to handle this case?

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that isn't working

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions