fix(types): declare runtime URL and URLSearchParams globals - #11482
Open
aleclarson wants to merge 1 commit into
Open
aleclarson wants to merge 1 commit into
aleclarson wants to merge 1 commit into
Conversation
Both runtimes have provided WHATWG URL and URLSearchParams natively since 8.7 (ada-url based), but nothing declared them for projects compiled without the DOM lib, so `new URL(...)` failed typecheck. Adds globals.d.ts to @nativescript/types declaring the runtime surface: URL with searchParams but no toJSON/parse/webkitURL, URLSearchParams with live entries/keys/values iterators and the newer delete/has value parameters. Shapes mirror lib.dom.d.ts so the interfaces merge cleanly when a project also includes the DOM lib; the var redeclaration is resolved by skipLibCheck, same tradeoff as @types/node.
|
View your CI Pipeline Execution ↗ for commit 1d5bb88
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
Contributor
|
Hello! Thanks for the contribution. While this works, can you make it similar to what node does instead, so it's impossible for us to conflict with the other global definitions of URL https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/web-globals/url.d.ts |
This branch has not been 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.
PR Checklist
What is the current behavior?
Both runtimes have exposed
URLandURLSearchParamsas globals since 8.7 (ada-url based;URLImpl/URLSearchParamsImpl+blob-url.jsinns-v8ios-runtimeandandroid-runtime), but nothing declares them for projects compiled without the DOM lib. With"lib": ["ESNext"]and"types": ["@nativescript/types"],new URL(...)fails typecheck even though it works at runtime.What is the new behavior?
Adds
packages/types/globals.d.ts, referenced from the package'sindex.d.ts, declaring the surface the runtimes actually implement:URL:hash/host/hostname/href/password/pathname/port/protocol/search/username(read-write),originandsearchParams(read-only),toString(); staticscanParse,createObjectURL,revokeObjectURL. Deliberately omitted because the runtimes don't implement them:toJSON(), staticparse(),webkitURL. The constructor's first parameter is typedstringbecause the runtime throws a TypeError for anything else (new URL(urlInstance)works in browsers but not on-device).URLSearchParams:size,append,delete(name, value?),get,getAll,has(name, value?),set,sort,toString,forEach, liveentries/keys/valuesiterators andSymbol.iterator. The constructor accepts a string, record,string[][], anotherURLSearchParams, or any iterable of pairs.The interface members mirror
lib.dom.d.tsexactly (includingreadonlymodifiers), so when a project also includes the DOM lib the interfaces merge without conflict and the DOMvardeclaration — which additionally declarestoJSON/parse— wins. As with any constructor global (@types/nodedoes the same), avarredeclaration vslib.dom.d.tsis reported as TS2403 whenskipLibCheckis disabled;skipLibCheckis on in this repo and the standard app configs.Placement note: these are runtime-provided globals, unlike the core-polyfilled globals (
fetch,setTimeout, ...) declared inpackages/core/global-types.d.ts, so they live in@nativescript/types— the typings entry point named in the issue — rather than in core.No committed test: the types packages have no test target/typings-test framework. Verified manually with
tsc5.9.3:lib: ["ESNext"],types: ["@nativescript/types"](issue's repro config, simulated published package layout):new URL(...),hostname,pathname,searchParams.get(),canParse,URLSearchParamsiteration all typecheck;toJSON/URL.parse/new URL(urlObj)correctly error.skipLibCheck: clean.lib: ["ESNext","DOM","DOM.Iterable"]+skipLibCheck: clean; DOM-only members resolve via the merged DOM declaration.Fixes #11456.