fix(cli/tsc): use Blob to detect web fetch globals in node/globals.d.cts#33583
Open
fibibot wants to merge 1 commit intodenoland:mainfrom
Open
fix(cli/tsc): use Blob to detect web fetch globals in node/globals.d.cts#33583fibibot wants to merge 1 commit intodenoland:mainfrom
Blob to detect web fetch globals in node/globals.d.cts#33583fibibot wants to merge 1 commit intodenoland:mainfrom
Conversation
…d.cts The vendored `@types/node` `globals.d.cts` heuristic falls back to undici types when `globalThis.onmessage` is absent. Deno only exposes `onmessage` on `globalThis` inside worker contexts, so under regular Deno code the LSP would resolve `RequestInit`, `Request`, `Response` etc. against undici and reject otherwise-valid `Parameters<typeof fetch>[1]` values. Switch the discriminator to detect `globalThis.Blob`, which is part of Deno's stable web platform globals. Also wire the rewrite into `tools/update_types_node.ts` so future @types/node syncs preserve it. Closes denoland#33012.
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.
Summary
The vendored
@types/nodeglobals.d.ctsusestypeof globalThis extends { onmessage: any }to decide whether to fall back to undici's web fetch types. Deno only exposesonmessageonglobalThisinside worker contexts, so in regular Deno code the LSP picks the undici types. As a result, otherwise-valid code likeis rejected by the LSP with
Argument of type 'global.RequestInit' is not assignable to parameter of type 'RequestInit', even thoughdeno checkpasses.This switches the discriminator from
onmessagetoBlob.Blobis part of Deno's stable web platform globals, so the conditional now correctly picks{}(deferring to Deno's own globals) instead of falling back to undici.This was previously attempted in #33037 directly editing
globals.d.cts. That PR was closed because the file is vendored and gets overwritten bytools/update_types_node.ts. This PR also wires the rewrite into the update script so the next@types/nodesync preserves it.Closes #33012.
Test plan
globals.d.ctsto use theBlobdiscriminatortools/update_types_node.tsso future regens preserve the changelsp_request_init_global_matches_checkopens the issue's repro and asserts no diagnosticscargo test -p integration_tests --test integration lsp_request_init_global_matches_checkpasses locallydeno checkon the issue's repro file passes