Skip to content

fix(types): declare runtime URL and URLSearchParams globals - #11482

Open
aleclarson wants to merge 1 commit into
NativeScript:mainfrom
aleclarson:fix/types-url-globals
Open

aleclarson wants to merge 1 commit into
NativeScript:mainfrom
aleclarson:fix/types-url-globals

Conversation

@aleclarson

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Both runtimes have exposed URL and URLSearchParams as globals since 8.7 (ada-url based; URLImpl/URLSearchParamsImpl + blob-url.js in ns-v8ios-runtime and android-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's index.d.ts, declaring the surface the runtimes actually implement:

  • URL: hash/host/hostname/href/password/pathname/port/protocol/search/username (read-write), origin and searchParams (read-only), toString(); statics canParse, createObjectURL, revokeObjectURL. Deliberately omitted because the runtimes don't implement them: toJSON(), static parse(), webkitURL. The constructor's first parameter is typed string because 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, live entries/keys/values iterators and Symbol.iterator. The constructor accepts a string, record, string[][], another URLSearchParams, or any iterable of pairs.

The interface members mirror lib.dom.d.ts exactly (including readonly modifiers), so when a project also includes the DOM lib the interfaces merge without conflict and the DOM var declaration — which additionally declares toJSON/parse — wins. As with any constructor global (@types/node does the same), a var redeclaration vs lib.dom.d.ts is reported as TS2403 when skipLibCheck is disabled; skipLibCheck is on in this repo and the standard app configs.

Placement note: these are runtime-provided globals, unlike the core-polyfilled globals (fetch, setTimeout, ...) declared in packages/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 tsc 5.9.3:

  • lib: ["ESNext"], types: ["@nativescript/types"] (issue's repro config, simulated published package layout): new URL(...), hostname, pathname, searchParams.get(), canParse, URLSearchParams iteration all typecheck; toJSON/URL.parse/new URL(urlObj) correctly error.
  • Same config without skipLibCheck: clean.
  • lib: ["ESNext","DOM","DOM.Iterable"] + skipLibCheck: clean; DOM-only members resolve via the merged DOM declaration.

Fixes #11456.

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.
@nx-cloud

nx-cloud Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 1d5bb88

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 30s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-30 18:55:17 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11482
npm i https://pkg.pr.new/@nativescript/vite@11482
npm i https://pkg.pr.new/@nativescript/webpack@11482

commit: 1d5bb88

@edusperoni

Copy link
Copy Markdown
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

No deployments
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.

URL and URLSearchParams globals lack native TypeScript declarations without DOM libs

2 participants