Skip to content

feat(wrangler): Add programmatic type generation API#13717

Merged
NuroDev merged 13 commits intomainfrom
NuroDev/programmatic-type-generation
Apr 30, 2026
Merged

feat(wrangler): Add programmatic type generation API#13717
NuroDev merged 13 commits intomainfrom
NuroDev/programmatic-type-generation

Conversation

@NuroDev
Copy link
Copy Markdown
Member

@NuroDev NuroDev commented Apr 29, 2026

Fixes RM-27721.

This change adds a programmatic Wrangler API for type generation via experimental_generateTypes, using the same core logic as wrangler types so CLI and API outputs stay aligned.

What's changed

  • Added a new experimental_generateTypes implementation
  • Refactored packages/wrangler/src/type-generation/index.ts to extract shared generation helpers used by both:
    • CLI (wrangler types)
    • Programmatic API (experimental_generateTypes)
  • Preserved existing CLI behavior (validation, output structure, logging, runtime guidance, and file writing).
  • Added JSDoc for newly introduced internal helper functions.
  • Added/merged API-focused tests into packages/wrangler/src/__tests__/type-generation.test.ts, including parity checks.

Usage

import { experimental_generateTypes } from 'wrangler';

const generated = await experimental_generateTypes({
  config: 'path/to/wrangler.jsonc',
  includeRuntime: false,
});

console.log(generated.content);
//                      ^? string

A picture of a cute animal (not mandatory, but encouraged)

@NuroDev NuroDev self-assigned this Apr 29, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 29, 2026

🦋 Changeset detected

Latest commit: c09a25b

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

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 29, 2026

Review posted on PR #13717 with two findings:

  1. Dead-code configPath check (medium) — In the CLI handler at lines 217-223, config.configPath is re-checked for undefined after assertConfigFileDetected already validated it during resolveGenerateTypesOptions. This block is unreachable after the refactoring and should be simplified.

  2. Duplicate GenerateTypesOptions interface (low) — The same interface is defined in both src/api/generate-types.ts and src/type-generation/index.ts. These should share a single definition to prevent silent drift.

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 29, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: c09a25b

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

✅ All changesets look good

Review of .changeset/many-baths-arrive.md:

  • Version Type: minor is appropriate for adding a new programmatic API feature
  • Changelog Quality: Clear description explaining the new experimental_generateTypes() API, its relationship to wrangler types, and the options it supports
  • Markdown Headers: No h1/h2/h3 headers present
  • Experimental Features: Appropriately marked as experimental in both the description and the function name (experimental_generateTypes())

@NuroDev NuroDev marked this pull request as ready for review April 29, 2026 10:13
@workers-devprod workers-devprod requested review from a team and dario-piotrowicz and removed request for a team April 29, 2026 10:14
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 29, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@petebacondarwin
Copy link
Copy Markdown
Contributor

Do we actually publicly document other unstable_ APIs?

@NuroDev
Copy link
Copy Markdown
Member Author

NuroDev commented Apr 29, 2026

Do we actually publicly document other unstable_ APIs?

Actually yes: https://developers.cloudflare.com/workers/wrangler/api/

Comment thread packages/wrangler/src/__tests__/type-generation.test.ts
Comment thread packages/wrangler/src/__tests__/type-generation.test.ts Outdated
Comment thread packages/wrangler/src/cli.ts
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🙂

Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Apr 29, 2026
@NuroDev NuroDev merged commit 9a1f014 into main Apr 30, 2026
52 checks passed
@NuroDev NuroDev deleted the NuroDev/programmatic-type-generation branch April 30, 2026 10:55
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Apr 30, 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.

4 participants