wrangler exposes experimental experimental_generateTypes() API
Introduced 2026-04-30 · score 0.92
HOW TO USE IT
When code needs Worker types from Wrangler’s generation logic, import `experimental_generateTypes` from `wrangler` and await it with an optional options object. Use its `env` and `runtime` strings or combined `content`; the API does not write the output to disk automatically.
import { experimental_generateTypes } from "wrangler";
const result = await experimental_generateTypes({
config: "<wrangler-config>",
includeRuntime: true,
includeEnv: true,
});
// Use result.env, result.runtime, or result.content.WHY THIS HELPS
Generate Worker types programmatically in code using Wrangler's type-generation logic.
REQUIREMENTS AND LIMITATIONS
- Version: 4.87.0
- Availability: experimental
- options: Optional options object mirroring core `wrangler types` options.
- config: Wrangler config path; accepts a string or array for multi-config type resolution.
- env: Wrangler environment name for type generation.
- includeEnv: Include environment and bindings types; defaults to `true`.
- includeRuntime: Include runtime types; defaults to `true`.
- envInterface: Name the generated environment interface; defaults to `Env`.
- envFile: Paths to `.env` files used to infer local variables and secrets.
- path: Target declaration file path; defaults to `worker-configuration.d.ts`.
- strictVars: Generate strict literal and union types for variables; defaults to `true`.
- Supports the same core type-generation options as `wrangler types`, including env/runtime toggles.
FIRST-PARTY EVIDENCE
- https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.87.0
- https://developers.cloudflare.com/workers/wrangler/api/
Check the installed version and the source before using it. Entry JSON