Skip to content

URL and URLSearchParams globals lack native TypeScript declarations without DOM libs #11456

Description

@aleclarson

Issue Description

NativeScript runtime support for URL and URLSearchParams is tracked in #10297, which lists both as available since 8.7. In a NativeScript TypeScript project that omits the browser DOM library, however, TypeScript cannot use these runtime-supported globals through @nativescript/types.

This is a build-time typing report; it does not claim that the runtime constructor is missing.

It would help if @nativescript/types exposed the supported URL and URLSearchParams globals without requiring the full DOM library, or documented the supported typing setup for this case. Enabling all DOM types also declares browser globals such as document that are unavailable in NativeScript apps, so it can hide accidental use of unsupported APIs.

Reproduction

With @nativescript/core 9.1.2, @nativescript/types 9.0.0, TypeScript 5.9.3, and this native compiler configuration:

{
  "compilerOptions": {
    "lib": ["ESNext"],
    "types": ["@nativescript/types", "vite/client"]
  }
}

Compile this code:

const url = new URL('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
console.log(url.hostname, url.pathname, url.searchParams.get('v'));

TypeScript reports:

TS2693: 'URL' only refers to a type, but is being used as a value here.
TS2339: Property 'hostname' does not exist on type 'URL'.
TS2339: Property 'pathname' does not exist on type 'URL'.
TS2339: Property 'searchParams' does not exist on type 'URL'.

Relevant log output (if applicable)

Build-time TypeScript diagnostics shown above. No runtime exception is being reported.

Environment

  • @nativescript/core: 9.1.2
  • @nativescript/types: 9.0.0
  • TypeScript: 5.9.3
  • Native tsconfig: lib: ["ESNext"], types: ["@nativescript/types", "vite/client"]

Please accept these terms

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions