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>;
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark