Skip to content

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

Merged
NathanWalker merged 2 commits into
NativeScript:mainfrom
aleclarson:fix/types-url-globals
Oct 6, 2026
Merged

NathanWalker merged 2 commits 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 9b21163

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 1s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-10-05 18:20:26 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: 9b21163

@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

Restructures the URL/URLSearchParams declarations after maintainer
feedback to follow the @types/node web-globals pattern: shapes live in
a module-scoped `url` namespace and are bound inside `declare global`.
The global interfaces extend the module types (merging with lib.dom's)
and the `var` declarations use `typeof globalThis extends
{ onmessage: any; URL: infer T } ? T : ...` so they adopt the type of
any existing global definition instead of conflicting with it — no more
TS2403 against lib.dom even without skipLibCheck.
@NathanWalker
NathanWalker merged commit 3939fe1 into NativeScript:main Oct 6, 2026
7 checks passed
aleclarson added a commit to octane-xplat/octane-xplat that referenced this pull request Oct 8, 2026
The ambient @nativescript/types URL declaration (no toJSON, matching the
native runtime) owns the global URL binding in app typecheck programs, so
new URL(...) in these node-side configs no longer satisfies fs PathLike,
which wants import("url").URL. Import the node class explicitly.

---

chore(deps): bump @nativescript/types to 9.1.4 and @octanejs/tiptap to 0.0.52

@nativescript/types 9.1.4 ships the URL/URLSearchParams ambient
declarations (NativeScript/NativeScript#11482), so the pnpm patch is
dropped entirely — manifest entry, patch file, and patchedDependencies.

@octanejs/tiptap 0.0.52 lands the './Context' disambiguation
(octanejs/octane#1502), so the patch shrinks to the remaining
process.env guard in useEditor.ts (closed unmerged upstream).

types-ios 9.1.3 tightens nullability: NSNotification.userInfo and
UIApplication.keyWindow are now nullable — optional-chain the
interruption observer reads in audio.ios and cast the keyWindow
fallback in auth-session.
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

3 participants