docs(cf-workers): document type-checking setup for the Wrangler tutorial#3362
Open
bartlomieju wants to merge 1 commit into
Open
docs(cf-workers): document type-checking setup for the Wrangler tutorial#3362bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Wrangler tutorial generates
worker-configuration.d.tsviacf-typegenand the example worker usessatisfies ExportedHandler<Env>, but the tutorial never configuresdeno.jsonto consume those generated types. Following it as written,deno check(and the editor) fails: with nothing wiring the file in,EnvandExportedHandlerare 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-typegenstep that sets acompilerOptionsblock indeno.json:lib: ["esnext"]drops Deno\x27s default Web/DOM globals so the workerd types fromworker-configuration.d.tsare the single source of truth (this mirrors thetsconfigCloudflare generates for Workers). For projects that also useDeno.*,["esnext", "deno.ns"]works too.types: ["./worker-configuration.d.ts"]loads the generated Workers types project-wide soEnvandExportedHandlerresolve.skipLibCheck: trueskips checking inside the generated declaration file.Verified on Deno 2.9.0 + Wrangler 4.105.0: with the block,
deno checkgoes from erroring to clean while real type checking stays active (e.g. a wrong handler signature is still flagged, andreqis correctly typed as the workerdRequest). Relates to denoland/deno#31487.