Setting the file. One moment.
Skill 13 · Workers Best Practices
Subchapter 13.2
references/platform-apis.mdMarkdown4 KBView on GitHub
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.
any, unknown, object, or Record<string, unknown> on bindings.Verify affected signatures against the project’s target type definitions; consult current docs if runtime support or compatibility remains uncertain.
"cloudflare:workers")DurableObject<Env>)ExecutionContext as the third param in module export handlers (needed for ctx.waitUntil())fetch() handlers must return Promise<Response>fetch, scheduled, queue, email): bindings via env.X parameterWorkerEntrypoint, DurableObject, Workflow, Agent): bindings via this.env.XFlag env.X inside a class extending a platform base class. Flag this.env.X inside a module export handler.
Old patterns survive in codebases long after APIs change.
extends vs implements: platform classes use extends, not implements. The implements pattern is legacy and loses this.ctx, this.env."cloudflare:workers" vs "cloudflare:workflows".this.state to this.ctx in Durable Objects. Search types to confirm.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 (opens in a new tab) | 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 (opens in a new tab) | Verify the step result against the documented serialization contract and the project’s Workflow types before flagging a value. |
| Durable Object KV storage (opens in a new tab) | storage.put() supports structured-clone values; do not apply a blanket ban on Map or Set. |
| Durable Object SQL (opens in a new tab) | Check bound parameters against the SQL API’s supported types. Encode objects explicitly for the intended column representation. |
| WebSocket messages (opens in a new tab) | Use send() with a string, ArrayBuffer, or ArrayBufferView; encode objects, for example with JSON.stringify(). |