Skip to content

Conversation

@penalosa
Copy link
Contributor

Fixes #9770.

The SELF export in cloudflare:test was typed as Fetcher without a type parameter, which prevented TypeScript from recognizing RPC methods when testing workers that extend WorkerEntrypoint.

This PR adds a ProvidedWorker interface that users can augment to provide their worker's type, allowing SELF to be properly typed as Service<T> for RPC-enabled workers:

import type MyWorker from "./src/index";

declare module "cloudflare:test" {
  interface ProvidedWorker {
    default: typeof MyWorker;
  }
}

// Now SELF will have your RPC methods typed:
const result = await SELF.myRpcMethod("test");

When ProvidedWorker.default is not set, SELF defaults to Fetcher for backward compatibility.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because: This is a type-only change that doesn't affect runtime behavior. Type checking passes via pnpm check --filter @cloudflare/vitest-pool-workers.
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: The type definitions include comprehensive JSDoc comments explaining how to use the new ProvidedWorker interface.

…LF for RPC workers

Add a ProvidedWorker interface that users can augment to provide their
worker's type, allowing SELF to be properly typed as Service<T> for
RPC-enabled workers that extend WorkerEntrypoint.

Fixes #9770
@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: a811f16

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link
Contributor

claude bot commented Jan 29, 2026

Claude finished @penalosa's task —— View job


Changeset Review

Todo List:

  • Read changeset guidelines
  • Read changeset file
  • Check image for cute animal
  • Validate changeset
  • Post review results

All changesets look good

The changeset .changeset/fix-self-type-for-rpc-workers.md passes all validation criteria:

  1. Version Type: patch is appropriate for a type improvement
  2. Changelog Quality: Clear title and detailed description with usage example
  3. Markdown Headers: No h1/h2/h3 headers used
  4. Analytics: Not applicable (no analytics changes)
  5. Dependabot: Not applicable (not a dependency update)
  6. Experimental features: Not applicable (not experimental)

The changeset follows all formatting guidelines with a clear imperative title, detailed explanation of the problem and solution, and a helpful code example showing how to use the new ProvidedWorker interface.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12281

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12281

miniflare

npm i https://pkg.pr.new/miniflare@12281

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12281

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12281

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12281

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12281

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12281

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12281

wrangler

npm i https://pkg.pr.new/wrangler@12281

commit: a811f16

@penalosa penalosa closed this Jan 29, 2026
@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The types for cloudflare:test expose self as a fetcher rather than a Service breaking types when testing rpc workers

1 participant