Skip to content

chore(types): generate Worker types with wrangler types, and drop the hand-picked @cloudflare/workers-types #89

Closed as not planned

Description

@sydevs-bot

Problem

@cloudflare/workers-types is a hand-picked devDependency, and picking its version is a recurring judgement call rather than a fact anyone can read off the config.

#84 was one round of that. PR #88 resolved it and showed the cost: [email protected] declares a peer of ^5.20260903.1, @universal-middleware/[email protected] declares ^4.20260608.1, and the ranges are disjoint. No single version satisfies both, so the PR had to argue for which unmet peer to prefer, and #84's acceptance criterion 2 ("no unmet peer") turned out to be unreachable as written.

The version is also picked to match the runtime by hand: [email protected] bundles [email protected], and 5.20260903.x is the types line for that date. Nothing enforces that pairing.

Separately, WEMEDITATE_CACHE: KVNamespace is hand-declared twice — types/vike.d.ts:67 and server/cms-context.ts:28 — while wrangler.toml:9-12 already declares the binding.

Proposal

Adopt Cloudflare's current guidance: wrangler types, which generates a worker-configuration.d.ts from the Wrangler config.

  • Runtime types come from the wrangler that emulates the runtime, matched to the compatibility_date and compatibility_flags we actually deploy with (2025-09-06, nodejs_compat).
  • The disjoint-peer trade above disappears with the dependency.
  • The generated Env interface is built from the declared bindings, so WEMEDITATE_CACHE stops being hand-declared.

What was confirmed — and what it turned up

⚠ The stated prerequisite passes. A different one fails, and it blocks the ticket as written.

wrangler.toml:4 sets main = "virtual:photon:cloudflare:server-entry". That is fine: wrangler types never resolves main, exits 0, and emits worker-configuration.d.ts (15,381 lines) whose Env types WEMEDITATE_CACHE: KVNamespace. Acceptance criterion 1 is met.

Criteria 3, 4 and 5 cannot all hold under one tsconfig.json. The generated file also declares the workerd runtime globals, and this repo has a single tsconfig with no include, so browser code and Worker code compile in one program. Committing the file and removing @cloudflare/workers-types turns a clean pnpm typecheck into two errors, both in code that runs in the browser:

  • components/organisms/RelatedContent/RelatedContentLoader.tsx:58 — workerd's Body.json<T>(): Promise<T> shadows the DOM's Promise<any>, so res.json() resolves to Promise<unknown>.
  • @ladle/react, inside its own bundled typings (typings-for-build/app/src/icons.tsx:55) — a global Element from the runtime types no longer satisfies EffectCallback.

Both were reproduced on main at c566dac: baseline pnpm typecheck is clean, and the two errors appear only once the generated file is in the program.

This is also why the hand-picked dependency was safe. It was only ever import type-ed, never listed in tsconfig.json's types, so its globals never entered the program at all. wrangler types has no equivalent import-only mode.

Open questions

  1. Which shape does this take? Neither is this ticket as written:
    • Give server/** its own tsconfig and scope the generated runtime types to it. Real work, and it changes what pnpm typecheck means.
    • Keep @cloudflare/workers-types and pin it deliberately, accepting that the disjoint peer stays a judgement call, and record the wrangler/workerd pairing somewhere a reader can check.
  2. Or close this. The problem it describes is real but small, and neither option above is clearly worth its cost.

Acceptance criteria

  1. wrangler types runs in this repo and emits worker-configuration.d.ts with WEMEDITATE_CACHE typed as a KV namespace. — confirmed, 2026-09-08.
  2. The generated file is either committed or generated in a postinstall/predev step — decide which, and say why in the PR.
  3. @cloudflare/workers-types is removed from devDependencies, and pnpm install reports no unmet peer for it.
  4. server/kv-cache.ts, server/cms-context.ts and types/vike.d.ts resolve KVNamespace from the generated types.
  5. pnpm typecheck, pnpm test:run and pnpm build pass; the Worker preview boots.

⚠ 3, 4 and 5 are not jointly satisfiable today — see above. Resolve the open questions before restoring Stage: Implement.

Origin

Raised as a consider finding on PR #88's adversarial review, scoped out of that PR at the time: #88 (comment)

🤖 Written by the sydevs autonomous loop — see what this is

Activity

  1. sydevs-bot commented on Sep 8, 2026

    @sydevs-bot
    ContributorAuthor

    Not viable as written — Stage moved back to Revising. The prerequisite it names passes; a different one fails.

    ✅ wrangler types runs here. The virtual main is never resolved, and the emitted Env types WEMEDITATE_CACHE: KVNamespace. AC 1 is met.

    ❌ AC 3 + 4 + 5 cannot all hold under one tsconfig.json. The file also declares workerd runtime globals, and this repo compiles browser and Worker code in one program. Committing it and dropping @cloudflare/workers-types turns a clean pnpm typecheck into two errors, both in browser code:

    • RelatedContentLoader.tsx:58 — workerd Body.json<T>(): Promise<T> shadows the DOM's Promise<any>, so res.json() is Promise<unknown>.
    • @ladle/react, in its own typings — a global Element no longer satisfies EffectCallback.

    The old dependency was safe for that reason: only ever import type-ed, so its globals never entered the program.

    Two options, neither this ticket: give server/** its own tsconfig, or keep @cloudflare/workers-types and pin it. Which? Closing is also fine.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  2. moved this from Revising to No status in SYDevelopers Technical Roadmapon Sep 9, 2026
  3. Ardnived commented on Sep 13, 2026

    @Ardnived
    Contributor

    Let's leave this as it is for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Priority

    Low

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions