Skip to content

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
fibibot:fix/lsp-requestinit-globals
Open

fix(cli/tsc): use Blob to detect web fetch globals in node/globals.d.cts#33583
fibibot wants to merge 1 commit intodenoland:mainfrom
fibibot:fix/lsp-requestinit-globals

Conversation

@fibibot
Copy link
Copy Markdown
Contributor

@fibibot fibibot commented Apr 27, 2026

Summary

The vendored @types/node globals.d.cts uses typeof globalThis extends { onmessage: any } to decide whether to fall back to undici's web fetch types. Deno only exposes onmessage on globalThis inside worker contexts, so in regular Deno code the LSP picks the undici types. As a result, otherwise-valid code like

const init: Parameters<typeof fetch>[1] = {};
const req = new Request("https://deno.com", init);

is rejected by the LSP with Argument of type 'global.RequestInit' is not assignable to parameter of type 'RequestInit', even though deno check passes.

This switches the discriminator from onmessage to Blob. Blob is 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 by tools/update_types_node.ts. This PR also wires the rewrite into the update script so the next @types/node sync preserves it.

Closes #33012.

Test plan

  • Updated globals.d.cts to use the Blob discriminator
  • Added a programmatic rewrite step in tools/update_types_node.ts so future regens preserve the change
  • New LSP regression test lsp_request_init_global_matches_check opens the issue's repro and asserts no diagnostics
  • cargo test -p integration_tests --test integration lsp_request_init_global_matches_check passes locally
  • deno check on the issue's repro file passes

…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.
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.

Bug: lsp has different type for RequestInit

1 participant