Skip to content

Commit

Permalink
🤖 Merge PR #58619 fix(node): make global URL decl compatible with lib…
Browse files Browse the repository at this point in the history
… "webworker" by @antongolub

* fix(node): make global ULR decl compatible with lib "webworker"

relates #58277 #34960

* fix(node): improve global URL var type resolution

* refactor(node): handle URLSeachParams var type collision in the same way as for URL

* refactor(node): simplify type condition for global URL and URLSearchParams
  • Loading branch information
antongolub committed Feb 14, 2022
1 parent 71ccdc3 commit 118a383
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
16 changes: 10 additions & 6 deletions types/node/url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,17 +869,21 @@ declare module 'url' {
* https://nodejs.org/api/url.html#the-whatwg-url-api
* @since v10.0.0
*/
var URL: typeof globalThis extends { webkitURL: infer URL } ? URL : typeof _URL;
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: any, URL: infer URL }
? URL
: typeof _URL;
/**
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`
* https://nodejs.org/api/url.html#class-urlsearchparams
* @since v10.0.0
*/
var URLSearchParams: {
prototype: URLSearchParams;
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
toString(): string;
};
var URLSearchParams:
// For compatibility with "dom" and "webworker" URLSearchParams declarations
typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams }
? URLSearchParams
: typeof _URLSearchParams;
}
}
declare module 'node:url' {
Expand Down
16 changes: 10 additions & 6 deletions types/node/v12/url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ declare module 'url' {
* https://nodejs.org/api/url.html#the-whatwg-url-api
* @since v10.0.0
*/
var URL: typeof globalThis extends { webkitURL: infer URL } ? URL : typeof _URL;
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: any, URL: infer URL }
? URL
: typeof _URL;
/**
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`.
* https://nodejs.org/api/url.html#class-urlsearchparams
* @since v10.0.0
*/
var URLSearchParams: {
prototype: URLSearchParams;
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
toString(): string;
};
var URLSearchParams:
// For compatibility with "dom" and "webworker" URLSearchParams declarations
typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams }
? URLSearchParams
: typeof _URLSearchParams;
}
}
16 changes: 10 additions & 6 deletions types/node/v14/url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,21 @@ declare module 'url' {
* https://nodejs.org/api/url.html#the-whatwg-url-api
* @since v10.0.0
*/
var URL: typeof globalThis extends { webkitURL: infer URL } ? URL : typeof _URL;
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: any, URL: infer URL }
? URL
: typeof _URL;
/**
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`.
* https://nodejs.org/api/url.html#class-urlsearchparams
* @since v10.0.0
*/
var URLSearchParams: {
prototype: URLSearchParams;
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
toString(): string;
};
var URLSearchParams:
// For compatibility with "dom" and "webworker" URLSearchParams declarations
typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams }
? URLSearchParams
: typeof _URLSearchParams;
}
}
declare module 'node:url' {
Expand Down
16 changes: 10 additions & 6 deletions types/node/v16/url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,17 +829,21 @@ declare module 'url' {
* https://nodejs.org/api/url.html#the-whatwg-url-api
* @since v10.0.0
*/
var URL: typeof globalThis extends { webkitURL: infer URL } ? URL : typeof _URL;
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: any, URL: infer URL }
? URL
: typeof _URL;
/**
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`.
* https://nodejs.org/api/url.html#class-urlsearchparams
* @since v10.0.0
*/
var URLSearchParams: {
prototype: URLSearchParams;
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
toString(): string;
};
var URLSearchParams:
// For compatibility with "dom" and "webworker" URLSearchParams declarations
typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams }
? URLSearchParams
: typeof _URLSearchParams;
}
}
declare module 'node:url' {
Expand Down

0 comments on commit 118a383

Please sign in to comment.