Cloudflare Docs
Workers
Edit this page on GitHub
Set theme to dark (⇧+D)

TypeScript

The @cloudflare/workers-types package provides the Service and DurableObjectNamespace types, each of which accepts a single type parameter for the server-side WorkerEntrypoint or DurableObject types.

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

For example:

interface Env {
SUM_SERVICE: Service<SumService>;
COUNTER_OBJECT: DurableObjectNamespace<Counter>
}
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>;