Skip to content

Commit

Permalink
feat(node): declare URL and URLSearchParams as globals
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jan 20, 2022
1 parent 721dbc0 commit 28295cf
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions types/node/index.d.ts
Expand Up @@ -120,6 +120,7 @@
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="url.globals.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
Expand Down
6 changes: 6 additions & 0 deletions types/node/test/url.ts
Expand Up @@ -167,3 +167,9 @@ import * as url from 'node:url';
{
const dataUrl: string = url.URL.createObjectURL(new Blob(['']));
}
{
const dataUrl1: URL = new url.URL('file://test');
const dataUrl2: url.URL = new URL('file://test');
const urlSearchParams1: URLSearchParams = new url.URLSearchParams();
const urlSearchParams2: url.URLSearchParams = new URLSearchParams();
}
2 changes: 1 addition & 1 deletion types/node/url.d.ts
Expand Up @@ -778,7 +778,7 @@ declare module 'url' {
* @param fn Invoked for each name-value pair in the query
* @param thisArg To be used as `this` value for when `fn` is called
*/
forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: this) => void, thisArg?: TThis): void;
forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void, thisArg?: TThis): void;
/**
* Returns the value of the first name-value pair whose name is `name`. If there
* are no such pairs, `null` is returned.
Expand Down
11 changes: 11 additions & 0 deletions types/node/url.globals.d.ts
@@ -0,0 +1,11 @@
import { URL as _URL, URLSearchParams as _URLSearchParams } from 'url';

declare global {
interface Global {
URL: typeof _URL;
URLSearchParams: typeof _URLSearchParams;
}

interface URLSearchParams extends _URLSearchParams {}
interface URL extends _URL {}
}
1 change: 1 addition & 0 deletions types/node/v12/index.d.ts
Expand Up @@ -82,6 +82,7 @@
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="url.globals.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
Expand Down
2 changes: 1 addition & 1 deletion types/node/v12/url.d.ts
Expand Up @@ -103,7 +103,7 @@ declare module 'url' {
append(name: string, value: string): void;
delete(name: string): void;
entries(): IterableIterator<[string, string]>;
forEach(callback: (value: string, name: string, searchParams: this) => void): void;
forEach(callback: (value: string, name: string, searchParams: URLSearchParams) => void): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
Expand Down
11 changes: 11 additions & 0 deletions types/node/v12/url.globals.d.ts
@@ -0,0 +1,11 @@
import { URL as _URL, URLSearchParams as _URLSearchParams } from 'url';

declare global {
interface Global {
URL: typeof _URL;
URLSearchParams: typeof _URLSearchParams;
}

interface URLSearchParams extends _URLSearchParams {}
interface URL extends _URL {}
}
1 change: 1 addition & 0 deletions types/node/v14/index.d.ts
Expand Up @@ -88,6 +88,7 @@
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="url.globals.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
Expand Down
7 changes: 7 additions & 0 deletions types/node/v14/test/url.ts
Expand Up @@ -154,3 +154,10 @@ import * as url from 'node:url';
{
const path: url.URL = url.pathToFileURL('file://test');
}

{
const dataUrl1: URL = new url.URL('file://test');
const dataUrl2: url.URL = new URL('file://test');
const urlSearchParams1: URLSearchParams = new url.URLSearchParams();
const urlSearchParams2: url.URLSearchParams = new URLSearchParams();
}
2 changes: 1 addition & 1 deletion types/node/v14/url.d.ts
Expand Up @@ -102,7 +102,7 @@ declare module 'url' {
append(name: string, value: string): void;
delete(name: string): void;
entries(): IterableIterator<[string, string]>;
forEach(callback: (value: string, name: string, searchParams: this) => void): void;
forEach(callback: (value: string, name: string, searchParams: URLSearchParams) => void, thisArg?: any): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
Expand Down
11 changes: 11 additions & 0 deletions types/node/v14/url.globals.d.ts
@@ -0,0 +1,11 @@
import { URL as _URL, URLSearchParams as _URLSearchParams } from 'node:url';

declare global {
interface Global {
URL: typeof _URL;
URLSearchParams: typeof _URLSearchParams;
}

interface URLSearchParams extends _URLSearchParams {}
interface URL extends _URL {}
}
1 change: 1 addition & 0 deletions types/node/v16/index.d.ts
Expand Up @@ -120,6 +120,7 @@
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="url.globals.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
Expand Down
6 changes: 6 additions & 0 deletions types/node/v16/test/url.ts
Expand Up @@ -167,3 +167,9 @@ import * as url from 'node:url';
{
const dataUrl: string = url.URL.createObjectURL(new Blob(['']));
}
{
const dataUrl1: URL = new url.URL('file://test');
const dataUrl2: url.URL = new URL('file://test');
const urlSearchParams1: URLSearchParams = new url.URLSearchParams();
const urlSearchParams2: url.URLSearchParams = new URLSearchParams();
}
2 changes: 1 addition & 1 deletion types/node/v16/url.d.ts
Expand Up @@ -738,7 +738,7 @@ declare module 'url' {
* @param fn Invoked for each name-value pair in the query
* @param thisArg To be used as `this` value for when `fn` is called
*/
forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: this) => void, thisArg?: TThis): void;
forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void, thisArg?: TThis): void;
/**
* Returns the value of the first name-value pair whose name is `name`. If there
* are no such pairs, `null` is returned.
Expand Down
11 changes: 11 additions & 0 deletions types/node/v16/url.globals.d.ts
@@ -0,0 +1,11 @@
import { URL as _URL, URLSearchParams as _URLSearchParams } from 'url';

declare global {
interface Global {
URL: typeof _URL;
URLSearchParams: typeof _URLSearchParams;
}

interface URLSearchParams extends _URLSearchParams {}
interface URL extends _URL {}
}

0 comments on commit 28295cf

Please sign in to comment.