@cloudflare/workers-types

Official TypeScript type definitions for the Cloudflare Workers runtime, covering fetch handlers and platform bindings like KV, D1, R2, and Durable Objects.

SDK
npm
v5.20261024.1
9,063 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
90 /100 Excellent
Development Activity 100
Maintenance 100
Community 64
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 82
Code Quality 80
Innovation 78
Learning Curve 90

@cloudflare/workers-types ships the ambient TypeScript declarations for everything a Cloudflare Worker can touch: the Workers runtime globals (Request, Response, ExecutionContext, ScheduledEvent, ExportedHandler) and the platform bindings that make Workers useful in production, including KV namespaces, D1 databases, R2 buckets, Durable Objects, Queues, Vectorize, Workers AI, and Hyperdrive. The types are generated directly from workerd’s own JSG RTTI (the C++ runtime’s structural type information), so they track the actual shape of the runtime rather than a hand-maintained guess.

Because Workers’ backward compatibility is governed by compatibility dates rather than semver, this package publishes a new version on roughly the same daily cadence as workerd itself, always representing the latest runtime surface. Cloudflare now recommends generating types scoped to a project’s specific compatibility date and flags via the wrangler types command instead, though this package continues to be published on the same schedule for projects that still depend on it directly.

What You Get

  • Ambient global types for the Workers runtime — Request, Response, ExecutionContext, FetchEvent, ScheduledEvent, and the rest of the standards-based global scope.
  • Typed bindings for Cloudflare’s storage and compute primitives — KVNamespace, D1Database, R2Bucket, DurableObjectNamespace, Queue, Vectorize, and AI.
  • An /experimental subpath export for APIs still gated behind experimental compatibility flags, kept separate from the stable surface.
  • Importable type aliases (e.g. import type { Request as WorkerRequest } from "@cloudflare/workers-types") for projects that can’t fully swap their global tsconfig.json lib/types configuration.

Common Use Cases

  • Adding compile-time type safety to a Worker’s fetch/scheduled/queue handlers and their Env bindings interface.
  • Getting IDE autocomplete for platform APIs (KV, D1, R2, Durable Objects) while writing Workers in TypeScript.
  • Type-checking a worker-configuration.d.ts file that declares a project’s specific bindings.
  • Providing a base typing environment for frameworks and tools (e.g. Hono, itty-router) that target the Workers runtime.

Under The Hood

Architecture

The generator pipeline (types/src/index.ts) turns workerd’s own JSG RTTI — a Cap’n Proto description of the runtime’s C++ structures — into TypeScript declarations: generateDefinitions() walks the RTTI into raw AST nodes, compileOverridesDefines() layers in hand-written override/define source files, and a chain of AST transforms (iterator, override-define, global-scope, class-to-interface, comments, add-onmessage-declaration) rewrites the program using TypeScript’s own compiler API (program.ts, print.ts) before a separate importable-variant pass produces the non-global export. The Cap’n Proto RTTI schema acts as a stable boundary between the C++ runtime and the TypeScript tooling, so the generator never has to parse C++ directly. The whole pipeline is invoked from Bazel (types/scripts/build-types.ts, build-worker.ts), and the npm publish step (npm/scripts/build-types-package.mjs) simply stamps the workerd release version onto the already-built declaration snapshot.

Tech Stack

The generator is written in TypeScript against TypeScript 6’s own compiler API (ts.Program, ts.TypeChecker, ts.transform), reads RTTI via capnp-es, and builds through the monorepo’s Bazel rules rather than a standalone npm build script. The published package itself has no runtime dependencies — it ships prebuilt .d.ts snapshots only — and is versioned in lockstep with workerd’s own dated releases via a WORKERD_VERSION environment variable written into package.json at build time.

Code Quality

The types/test directory carries real coverage: generator unit tests (structure, type, index), print-output snapshot tests, transform-specific tests (iterators, class-to-interface, globals, overrides), and a types/test/types directory of realistic usage snippets (D1, Durable Objects, email, RPC, AI, Cloudflare-specific properties) that are type-checked against the generated declarations as an integration check. Linting runs through a shared typescript-eslint base config, with a short, explicitly tracked list of relaxed rules (e.g. no-unnecessary-condition) called out as TODOs rather than silently disabled. tsconfig relaxes strictNullChecks for compatibility reasons but keeps checkJs and most strict flags on.

API Design The generated-from-RTTI approach is the notable choice here: instead of a hand-maintained @types package that drifts from the runtime it describes (a common failure mode for community type definitions), these types are produced from the same structural metadata the C++ runtime itself exposes, so a new runtime capability shows up in the types the moment it ships. The dual ambient/importable output and the isolated /experimental subpath mirror the platform’s own compatibility-date philosophy: stable and experimental surfaces are kept structurally separate rather than mixed behind version numbers, and consumers can opt into either the zero-config global setup or scoped type-only imports depending on how much of their tsconfig they’re willing to change.

Used by 29 apps in this directory

MDX
50%
Apache 2.0

Formizee

Forms Surveys

184

An open-source form backend and builder platform — design forms, collect submissions, and get analytics without hosting your own server, positioned as an alternative to Formspree and Typeform.

View details
30
Repo Health
59
Technical
67
Dependency
Built with
MDX 50%
TypeScript 49%
Updated 1 years ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,235

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
74
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 6 days ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,384

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
76
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 1 weeks ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

483

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
90
Repo Health
81
Technical
68
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
96%
AGPL 3.0

Libra AI

AI Development · No Code Platforms

1,695

Open-source AI-powered platform that generates and deploys full-stack web applications from natural language prompts, built natively for Cloudflare Workers.

View details
31
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 years ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

29,041

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
90
Repo Health
73
Technical
65
Dependency
Built with
TypeScript 99%
Updated 6 days ago
TypeScript
85%
GPL 3.0

Notesnook

File Storage · Note Taking · Security

14,822

End-to-end encrypted, open-source note-taking where your data stays yours — even from the server.

View details
91
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 85%
JavaScript 12%
Updated 6 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
94%
MIT

open-seo

Developer Tools · Marketing

24,707

Pay-as-you-go open source SEO platform with MCP integration — keyword research, rank tracking, backlinks, site audits, and AI brand visibility in one self-hosted tool.

View details
83
Repo Health
79
Technical
74
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers