Skip to content

docs(cf-workers): document type-checking setup for the Wrangler tutorial#3362

Open
bartlomieju wants to merge 1 commit into
mainfrom
docs/cf-workers-deno-typecheck
Open

docs(cf-workers): document type-checking setup for the Wrangler tutorial#3362
bartlomieju wants to merge 1 commit into
mainfrom
docs/cf-workers-deno-typecheck

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

The Wrangler tutorial generates worker-configuration.d.ts via cf-typegen and the example worker uses satisfies ExportedHandler<Env>, but the tutorial never configures deno.json to consume those generated types. Following it as written, deno check (and the editor) fails: with nothing wiring the file in, Env and ExportedHandler are not found; and once the file is wired in, Deno reports many conflicting global declarations, because Deno ships its own Web API globals (Request, Response, EventTarget, and the rest) alongside the workerd types declared in the generated file.

This adds a short Configure type checking section after the cf-typegen step that sets a compilerOptions block in deno.json:

  • lib: ["esnext"] drops Deno\x27s default Web/DOM globals so the workerd types from worker-configuration.d.ts are the single source of truth (this mirrors the tsconfig Cloudflare generates for Workers). For projects that also use Deno.*, ["esnext", "deno.ns"] works too.
  • types: ["./worker-configuration.d.ts"] loads the generated Workers types project-wide so Env and ExportedHandler resolve.
  • skipLibCheck: true skips checking inside the generated declaration file.

Verified on Deno 2.9.0 + Wrangler 4.105.0: with the block, deno check goes from erroring to clean while real type checking stays active (e.g. a wrong handler signature is still flagged, and req is correctly typed as the workerd Request). Relates to denoland/deno#31487.

The Wrangler tutorial generates worker-configuration.d.ts and uses
ExportedHandler<Env>, but never configures deno.json to consume those types.
As written, deno check cannot find Env/ExportedHandler; once the generated
file is wired in, Deno reports many conflicting global declarations because it
ships its own Web API globals alongside the workerd types.

Add a Configure type checking section showing the compilerOptions
(lib: [esnext], types, skipLibCheck) that makes the workerd types the single
source of truth, so deno check and editors type-check the worker correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant