Skip to content

Commit f97b9a5

Browse files
Manish Balayanmeta-codesync[bot]
authored andcommitted
fix(types): add missing standard properties to URL and URLSearchParams (#54787)
Summary: This PR related to issue #54789 updates the `URL` and `URLSearchParams` definitions in `globals.d.ts` to include missing standard properties and methods that are already supported by the runtime implementation. **Motivation:** I noticed that while the runtime supports standard URL operations (backed by `whatwg-url`), the TypeScript definitions were incomplete, causing unnecessary type errors when using standard Web APIs. ## Changelog: [GENERAL] [FIXED] - Added missing standard properties to `URL` (hash, host, pathname, etc.) and methods to `URLSearchParams` (get, set, delete, etc.). Pull Request resolved: #54787 Test Plan: 1. Open `globals.d.ts`. 2. Verify that `URL` interface now includes all standard properties. 3. Verify that `URLSearchParams` interface now includes all standard methods. 4. Verify that no new TypeScript errors are introduced. Screenshot: Before making changes <img width="1512" height="982" alt="Screenshot 2025-12-04 at 11 38 58 PM" src="https://github.com/user-attachments/assets/1b3bd18e-0f3e-476c-824f-a6b537092755" /> After making changes ![Uploading Screenshot 2025-12-04 at 11.39.42 PM.png…]() Reviewed By: javache Differential Revision: D88517037 Pulled By: alanleedev fbshipit-source-id: 9225b86e134be27dac7b135370de5266d414afb4
1 parent dc73ec4 commit f97b9a5

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

packages/react-native/src/types/globals.d.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,18 @@ declare global {
461461
| 'text';
462462

463463
interface URL {
464-
href: string;
464+
readonly hash: string;
465+
readonly host: string;
466+
readonly hostname: string;
467+
readonly href: string;
468+
readonly origin: string;
469+
readonly password: string;
470+
readonly pathname: string;
471+
readonly port: string;
472+
readonly protocol: string;
473+
search: string;
465474
readonly searchParams: URLSearchParams;
475+
readonly username: string;
466476

467477
toJSON(): string;
468478
toString(): string;
@@ -479,8 +489,27 @@ declare global {
479489
* Based on definitions of lib.dom and lib.dom.iterable
480490
*/
481491
interface URLSearchParams {
492+
/**
493+
* Returns the number of search parameter entries.
494+
*/
495+
readonly size: number;
496+
482497
append(key: string, value: string): void;
498+
delete(name: string): void;
499+
get(name: string): string | null;
500+
getAll(name: string): string[];
501+
has(name: string): boolean;
502+
set(name: string, value: string): void;
503+
sort(): void;
483504
toString(): string;
505+
forEach(
506+
callbackfn: (value: string, key: string, parent: URLSearchParams) => void,
507+
thisArg?: any,
508+
): void;
509+
510+
keys(): IterableIterator<string>;
511+
values(): IterableIterator<string>;
512+
entries(): IterableIterator<[string, string]>;
484513

485514
[Symbol.iterator](): IterableIterator<[string, string]>;
486515
}

0 commit comments

Comments
 (0)