Skip to content

Fix wrangler types --check ignoring --env-interface and secondary--config entries#13572

Merged
dario-piotrowicz merged 3 commits intomainfrom
dario/types-check-fix
Apr 20, 2026
Merged

Fix wrangler types --check ignoring --env-interface and secondary--config entries#13572
dario-piotrowicz merged 3 commits intomainfrom
dario/types-check-fix

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Apr 16, 2026

Fixes #13508

Previously, wrangler types --check ran its staleness check before resolving the --env-interface flag and before collecting secondary worker entry points from additional --config arguments. This meant it could incorrectly report types as up to date when they were actually stale due to a different env interface name or changes in secondary worker configs. The check now runs after all options are fully resolved, so it correctly detects mismatches.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix

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


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: 26ac991

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

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 16, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 16, 2026

I've now reviewed all the relevant code. Let me analyze the changes:

Summary of changes:

  1. The --check block in index.ts handler is moved from before secondary config resolution to after it, so envInterface and secondaryEntries are properly populated.
  2. checkTypesUpToDate in helpers.ts gains two new parameters: envInterface (optional override) and serviceEntries (map of secondary worker entries).
  3. The envInterface parameter, when provided, takes precedence over the value parsed from the file header.
  4. Comprehensive tests cover the fix for both --env-interface and multi-config scenarios.

Analysis:

The logic is sound. The envInterface override in helpers.ts:204 correctly uses envInterface ?? ((rawArgs.envInterface ?? "Env") as string) — if the caller provides an envInterface, it's used; otherwise, the value from the file header is used as before.

One thing I want to verify: when envInterface is "Env" (the default from yargs), it will still be passed as a non-undefined string. This means the override will always take effect when called from the handler. Let me check if this could cause issues for the case where the header recorded a different interface name...

Looking at the call site in index.ts:213-217:

const outOfDate = await checkTypesUpToDate(
    config,
    outputPath,
    envInterface,     // always a string ("Env" by default from yargs)
    secondaryEntries
);

And in helpers.ts:204:

envInterface: envInterface ?? ((rawArgs.envInterface ?? "Env") as string),

Since envInterface from args is always a string (never undefined, because yargs provides a default of "Env"), the ?? will never fall through to the header-parsed value. This is actually the correct behavior for --check: you want to compare what the user is requesting NOW (including the default "Env") against what's in the file. If the file was generated with --env-interface MyEnv and the user runs --check without specifying --env-interface, it should use "Env" (the default) and correctly detect a mismatch.

However, the other caller checkTypesDiff (used during wrangler dev, not modified in this PR) doesn't pass envInterface or serviceEntries, so it gets the old behavior via the default parameter values. That's fine — it wasn't broken and the function signature is backward compatible.

The tests are thorough and cover the key scenarios. The changeset is appropriate.

LGTM

github run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

✅ All changesets look good

Reviewed: .changeset/light-hairs-allow.md

Validation Results:

  • Version Type: patch is appropriate for this bug fix
  • Changelog Quality: Description is clear, explains the bug (staleness check running before options were resolved) and the fix
  • Markdown Headers: No h1/h2/h3 headers found
  • Analytics: N/A - not an analytics change
  • Dependabot: N/A - not a dependency update
  • Experimental Features: N/A - not an experimental feature change

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 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 16, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 26ac991

Comment thread packages/wrangler/src/type-generation/helpers.ts Outdated
Comment thread packages/wrangler/src/__tests__/type-generation.test.ts
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 17, 2026
@dario-piotrowicz dario-piotrowicz merged commit a610749 into main Apr 20, 2026
61 of 63 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/types-check-fix branch April 20, 2026 14:52
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Apr 20, 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.

wrangler types --check ignores --env-interface, -c, and other flags, always comparing against default output

3 participants