Skip to content

Conversation

@HW13
Copy link

@HW13 HW13 commented Nov 29, 2025

Fixes #10020

Describe your change...

Wrangler types command now adds a BaseEnv interface which is then extended by Cloudflare.Env and the --env-interface. Example output:

/* eslint-disable */
// Generated by Wrangler by running \`wrangler types --env-interface MyCloudflareEnv --include-runtime=false\` (hash: ...)
interface BaseEnv {
	MY_VAR: "my-var-value";
}
declare namespace Cloudflare {
	interface GlobalProps {
		mainModule: typeof import("./src/index");
	}
	interface Env extends BaseEnv {}
}
interface MyCloudflareEnv extends BaseEnv {}

While this doesn't outright resolve #10020, it ensures that the env-interface for each worker no longer depends on the namespace. This allows it to be explicitly passed into the WorkerEntrypoint or type cast to the env - which will prevent issues with conflicting Cloudflare namespaces.

import { WorkerEntrypoint } from 'cloudflare:workers'

export class MyService extends WorkerEntrypoint<MyCloudflareEnv> {
  // ...
}
import { env } from 'cloudflare:workers'

export const myCloudflareEnv = env as MyCloudflareEnv

  • Tests
    • Tests included/updated
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: References to the worker-configuration.d.ts in the docs appear to be intentionally simplified and don't include the Cloudflare namespace (example)
    • Wrangler PR:
    • Not necessary because: Not sure about this one, happy to do it if needed though

@HW13 HW13 requested a review from a team as a code owner November 29, 2025 22:31
@changeset-bot
Copy link

changeset-bot bot commented Nov 29, 2025

🦋 Changeset detected

Latest commit: f4cfded

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 2, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 3d44a76

@HW13 HW13 force-pushed the typegen-env-fix branch 2 times, most recently from a4a0f2d to 9d1e9ab Compare December 5, 2025 18:35
@HW13
Copy link
Author

HW13 commented Dec 6, 2025

Tests have been updated and the latest changes from main have been rebased into this branch. Could I please get workflow approval? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

ambient namespace for Env breaks types for subworkers with service bindings

1 participant