Repository navigation
Box URL into checked-dynamic unions beside fetch's Request and Response - #1459
Merged
Merged
Conversation
fetch's input under @types/node is string | URL | Request. A union with a checked-dynamic arm collapses to the checked-dynamic representation only when every sibling survives the collapse; URL did not qualify, so the type (and anything typed as typeof globalThis.fetch, such as a custom fetch cast through unknown) did not compile. URL's handle boxes by reference, keeps its accessors and setters, answers instanceof URL and checks back out to the typed value, so URL arms now join the collapse. A fetch() input typed string | URL also converts through the checked-dynamic input path instead of being narrowed to a string, which threw on the URL arm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Box URL into checked-dynamic unions beside fetch's Request and Response
Stacked on #1435.
Summary
Under @types/node,
fetch's input isstring | URL | Request. A union that holds a checked-dynamic arm, such as fetch'sRequesthandle, collapses to the checked-dynamic representation only when every other arm survives that collapse. URL did not, so the union was refused. The same refusal hit everything typed astypeof globalThis.fetch, including the common pattern of casting a custom fetch throughunknown:URL's checked-dynamic handle already exists and boxes by reference:
href,pathname,searchParamsand the other members through the native accessors;instanceof URL;So nothing degrades when a URL arm joins the collapse.
string | URL,string | URL | Requestand similar unions now compile.The second change is in
fetch()itself. An input typedstring | URL(a union without a checked-dynamic arm) was narrowed to a string at the call, which threw on the URL arm. Such an input now goes through fetch's existing checked-dynamic input path, which reads the URL'shref, as the bare-URL form does.Programs that don't spell such a union are unaffected. Every other union keeps its existing representation and fences.
URLSearchParamsstays out of the collapse becauseinstanceof URLSearchParamson a checked-dynamic value is not supported.Evidence
tests/fixtures/node-types/fetch-input-unions.ts, compiled under @types/node throughproject-config.test.ts, and the same program as corpus6252-fetch-input-url-unionsunder scriptc's own declarations. Both are run against Node. They cover:typeof globalThis.fetch;Record<string, unknown>;fetchwith string and URL inputs;string | Request | URLparameter narrowed withinstanceof URL, read, written through setters, and read throughsearchParams.test:ts7 --baselines-only(2 new baselines, none changed).🤖 Generated with Claude Code