diff --git a/src/content/changelog/workers/2026-01-13-wrangler-types-multi-environment.mdx b/src/content/changelog/workers/2026-01-13-wrangler-types-multi-environment.mdx new file mode 100644 index 000000000000000..d30a552b6045630 --- /dev/null +++ b/src/content/changelog/workers/2026-01-13-wrangler-types-multi-environment.mdx @@ -0,0 +1,27 @@ +--- +title: "`wrangler types` now generates types for all environments" +description: The `wrangler types` command now aggregates bindings from all environments by default, ensuring complete type coverage across your deployment environments. +products: + - workers +date: 2026-01-13 +--- + +The `wrangler types` command now generates TypeScript types for bindings from **all environments** defined in your Wrangler configuration file by default. + +Previously, `wrangler types` only generated types for bindings in the top-level configuration (or a single environment when using the `--env` flag). This meant that if you had environment-specific bindings — for example, a KV namespace only in production or an R2 bucket only in staging — those bindings would be missing from your generated types, causing TypeScript errors when accessing them. + +Now, running `wrangler types` collects bindings from all environments and includes them in the generated `Env` type. This ensures your types are complete regardless of which environment you deploy to. + +## Type conflict detection + +If the same binding name exists with different types across environments (for example, `CACHE` is a KV namespace in one environment but an R2 bucket in another), Wrangler will throw an error to prevent type conflicts. + +## Generating types for a specific environment + +If you want the previous behavior of generating types for only a specific environment, you can use the `--env` flag: + +```sh +wrangler types --env production +``` + +Learn more about [generating types for your Worker](/workers/wrangler/commands/#types) in the Wrangler documentation. diff --git a/src/content/docs/workers/wrangler/commands.mdx b/src/content/docs/workers/wrangler/commands.mdx index 4ce9bf902d6fe93..47ba2ea107362cd 100644 --- a/src/content/docs/workers/wrangler/commands.mdx +++ b/src/content/docs/workers/wrangler/commands.mdx @@ -968,9 +968,23 @@ wrangler types [] [OPTIONS] ::: +### Multi-environment support + +By default, `wrangler types` generates types for bindings from **all environments** defined in your configuration file. This ensures your generated `Env` type includes all bindings that might be used across different deployment environments (such as staging and production), preventing TypeScript errors when accessing environment-specific bindings. + +For example, if you have a KV namespace binding only in production and an R2 bucket binding only in staging, both will be included in the generated types. + +If the same binding name exists with different types across environments (for example, `CACHE` is a KV namespace in one environment but an R2 bucket in another), Wrangler will throw an error to prevent type conflicts. + +To generate types for only a specific environment, use the `--env` flag. + +### Options + - `PATH` - The path to where types for your Worker will be written. - The path must have a `d.ts` extension. +- `--env` + - Generate types for bindings in a specific environment only, rather than aggregating bindings from all environments. - `--env-interface` - The name of the interface to generate for the environment object. - Not valid if the Worker uses the Service Worker syntax.