platform-apis.md
| source_path | references/platform-apis.md |
|---|---|
| source_sha256 | 9ca9f5a7a82f92de45d310f5e2ee05aa464ddb7a63a737529caa17fff3660f28 |
| source_url | https://github.com/cloudflare/skills/blob/47dfc2ce969bf62acf8bc231198ade4bb02712e0/skills/workers-best-practices/references/platform-apis.md |
| supporting_skill_id | 40196 |
| upstream_revision | 47dfc2ce969bf62acf8bc231198ade4bb02712e0 |
Workers Platform API Checks
Use the project's installed and generated types to check affected handlers and bindings. Consult current Cloudflare docs when API or runtime compatibility remains uncertain.
- Type validation: binding types, handler signatures, and platform classes
- Serialization boundaries: encoding and supported values for each API
Type Validation
Env interface
- Every binding must have a specific type. Flag
any,unknown,object, orRecord<string, unknown>on bindings. - Binding types that accept generic parameters (Durable Object namespaces, Queues, Service bindings for RPC) must include them. Read the type definition to confirm which types are generic.
- Use the project's generated binding types; see configuration guidance.
Handler and class signatures
Verify affected signatures against the project's target type definitions; consult current docs if runtime support or compatibility remains uncertain.
- Correct import path (most Workers platform classes import from
"cloudflare:workers") - Generic type parameter on base classes (e.g.,
DurableObject<Env>) ExecutionContextas the third param in module export handlers (needed forctx.waitUntil())fetch()handlers must returnPromise<Response>
Binding access — the most common error
- Module export handlers (
fetch,scheduled,queue,email): bindings viaenv.Xparameter - Platform base classes (
WorkerEntrypoint,DurableObject,Workflow,Agent): bindings viathis.env.X
Flag env.X inside a class extending a platform base class. Flag this.env.X inside a module export handler.
Stale class patterns
Old patterns survive in codebases long after APIs change.
extendsvsimplements: platform classes useextends, notimplements. Theimplementspattern is legacy and losesthis.ctx,this.env.- Import paths: verify module specifiers match what types actually export. Common mistake: wrong path for
"cloudflare:workers"vs"cloudflare:workflows". - Renamed properties: e.g.,
this.statetothis.ctxin Durable Objects. Search types to confirm. - Constructor signatures: base class constructors change. Verify expected parameters.
Serialization Boundaries
Check the API and encoding at each boundary. Structured clone support does not imply JSON compatibility or SQL parameter support.
| Boundary | What to check |
|---|---|
| Queue messages | Match the body to contentType: json requires JSON-compatible data, text a string, bytes an ArrayBuffer, and v8 supports structured-clone values such as Map and Date. Check the configured compatibility date when relying on the default encoding. |
| Workflow step results | Verify the step result against the documented serialization contract and the project's Workflow types before flagging a value. |
| Durable Object KV storage | storage.put() supports structured-clone values; do not apply a blanket ban on Map or Set. |
| Durable Object SQL | Check bound parameters against the SQL API's supported types. Encode objects explicitly for the intended column representation. |
| WebSocket messages | Use send() with a string, ArrayBuffer, or ArrayBufferView; encode objects, for example with JSON.stringify(). |
Children
No children yet.
Like how this is organised?
Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.