Skip to content

[wrangler] Fix types --strict-vars=false emitting invalid TypeScript for an empty array var - #14889

Open
chinesepowered wants to merge 1 commit into
cloudflare:mainfrom
chinesepowered:fix-types-empty-array-var
Open

[wrangler] Fix types --strict-vars=false emitting invalid TypeScript for an empty array var#14889
chinesepowered wants to merge 1 commit into
cloudflare:mainfrom
chinesepowered:fix-types-empty-array-var

Conversation

@chinesepowered

@chinesepowered chinesepowered commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #14886.

wrangler types --strict-vars=false emitted ()[] for any var whose value is an empty array. typeofArray derives the element types from the array's contents, so an empty array yields zero types and falls through to the join branch with an empty list — the length === 1 and length >= 2 cases were handled, length === 0 was not.

Because this output lands in the generated worker-configuration.d.ts, the impact is not limited to the one line: ()[] is a syntax error, so the entire file fails to parse and no binding types resolve for the project.

An empty array now generates unknown[]. never[] would also be valid, but would make appends a type error for anyone who populates the var at runtime.


  • 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: this fixes invalid output from an existing documented flag; the flag's behaviour is otherwise unchanged.

The empty-array case is covered by adding varArrEmpty: [] to the existing should allow opting out of strict-vars test, which is the canonical enumeration of var shapes under --strict-vars=false. I confirmed it fails without the source change:

- 	varArrEmpty: unknown[];
+ 	varArrEmpty: ()[];

Full type-generation.test.ts suite passes (112 tests).


Open in Devin Review

typeofArray derived element types from the array's contents, so an empty
array produced zero types and fell through to the join branch with an
empty list, emitting ()[]. That is a syntax error, and since it lands in
worker-configuration.d.ts it broke the whole generated file rather than
just the one line.
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e0265a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 28, 2026
@workers-devprod
workers-devprod requested review from a team and penalosa and removed request for a team July 28, 2026 02:11
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/types-empty-array-var.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/type-generation.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/type-generation/index.ts: [@cloudflare/wrangler]

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

Copy link
Copy Markdown
Contributor

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 bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14889

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14889

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14889

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14889

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: e0265a8

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.

[wrangler] types --strict-vars=false emits invalid TypeScript ()[] for an empty array var

2 participants