TypeScript (2)

Last updated Apr 23, 2026 Running wrangler types generates runtime types including the Service and DurableObjectNamespace types, each of which accepts a single type parameter for the WorkerEntrypoint or DurableObject types.

Using higher-order types, we automatically generate client-side stub types (e.g., forcing all methods to be async).

wrangler types also generates types for the env object. You can pass in the path to the config files of the Worker or Durable Object being called so that the generated types include the type parameters for the Service and DurableObjectNamespace types.

For example, if your client Worker had bindings to a Worker in ../sum-worker/ and a Durable Object in ../counter/, you should generate types for the client Worker's env by running:

npmyarnpnpm

npx wrangler types -c ./client/wrangler.jsonc -c ../sum-worker/wrangler.jsonc -c ../counter/wrangler.jsonc
yarn wrangler types -c ./client/wrangler.jsonc -c ../sum-worker/wrangler.jsonc -c ../counter/wrangler.jsonc
pnpm wrangler types -c ./client/wrangler.jsonc -c ../sum-worker/wrangler.jsonc -c ../counter/wrangler.jsonc

This will produce a worker-configuration.d.ts file that includes:

worker-configuration.d.tsts

interface Env {
    SUM_SERVICE: Service<import("../sum-worker/src/index").SumService>;
    COUNTER_OBJECT: DurableObjectNamespace<
        import("../counter/src/index").Counter
    >;
}

Now types for RPC method like the env.SUM_SERVICE.sum method will be exposed to the client Worker.

src/index.tsts

export default {
    async fetch(req, env, ctx): Promise<Response> {
        const result = await env.SUM_SERVICE.sum(1, 2);
        return new Response(result.toString());
    },
} satisfies ExportedHandler<Env>;

Was this helpful?

YesNo

On this page

TypeScript (2) - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/rpc/typescript/#page","headline":"TypeScript","description":"How TypeScript types for your Worker or Durable Object's RPC methods are generated and exposed to clients","url":"https://developers.cloudflare.com/workers/runtime-apis/rpc/typescript/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/rpc/typescript/og.png?v=4357577e18058c65","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Which properties are and are not exposed to clients that communicate with your Worker or Durable Object via RPC title: Visibility and Security Model image: https://developers.cloudflare.com/workers/runtime-apis/rpc/visibility/og.png?v=4d324321c7d52802


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.