Skip to content

Commit a4e6873

Browse files
Add URL to RequestInfo typedef (#1269)
Co-authored-by: saschanaz <[email protected]>
1 parent 84dea31 commit a4e6873

File tree

5 files changed

+48
-41
lines changed

5 files changed

+48
-41
lines changed

baselines/dom.generated.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -3295,13 +3295,13 @@ declare var CSSTransition: {
32953295
* Available only in secure contexts.
32963296
*/
32973297
interface Cache {
3298-
add(request: RequestInfo): Promise<void>;
3298+
add(request: RequestInfo | URL): Promise<void>;
32993299
addAll(requests: RequestInfo[]): Promise<void>;
3300-
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
3301-
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
3302-
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
3303-
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
3304-
put(request: RequestInfo, response: Response): Promise<void>;
3300+
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
3301+
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
3302+
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
3303+
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
3304+
put(request: RequestInfo | URL, response: Response): Promise<void>;
33053305
}
33063306

33073307
declare var Cache: {
@@ -3317,7 +3317,7 @@ interface CacheStorage {
33173317
delete(cacheName: string): Promise<boolean>;
33183318
has(cacheName: string): Promise<boolean>;
33193319
keys(): Promise<string[]>;
3320-
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
3320+
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
33213321
open(cacheName: string): Promise<Cache>;
33223322
}
33233323

@@ -11405,7 +11405,7 @@ interface Request extends Body {
1140511405

1140611406
declare var Request: {
1140711407
prototype: Request;
11408-
new(input: RequestInfo, init?: RequestInit): Request;
11408+
new(input: RequestInfo | URL, init?: RequestInit): Request;
1140911409
};
1141011410

1141111411
interface ResizeObserver {
@@ -16642,7 +16642,7 @@ interface WindowOrWorkerGlobalScope {
1664216642
clearTimeout(id?: number): void;
1664316643
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
1664416644
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
16645-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
16645+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
1664616646
queueMicrotask(callback: VoidFunction): void;
1664716647
reportError(e: any): void;
1664816648
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
@@ -17928,7 +17928,7 @@ declare function clearInterval(id?: number): void;
1792817928
declare function clearTimeout(id?: number): void;
1792917929
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
1793017930
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
17931-
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
17931+
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
1793217932
declare function queueMicrotask(callback: VoidFunction): void;
1793317933
declare function reportError(e: any): void;
1793417934
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

baselines/serviceworker.generated.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,13 @@ declare var ByteLengthQueuingStrategy: {
781781
* Available only in secure contexts.
782782
*/
783783
interface Cache {
784-
add(request: RequestInfo): Promise<void>;
784+
add(request: RequestInfo | URL): Promise<void>;
785785
addAll(requests: RequestInfo[]): Promise<void>;
786-
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
787-
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
788-
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
789-
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
790-
put(request: RequestInfo, response: Response): Promise<void>;
786+
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
787+
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
788+
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
789+
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
790+
put(request: RequestInfo | URL, response: Response): Promise<void>;
791791
}
792792

793793
declare var Cache: {
@@ -803,7 +803,7 @@ interface CacheStorage {
803803
delete(cacheName: string): Promise<boolean>;
804804
has(cacheName: string): Promise<boolean>;
805805
keys(): Promise<string[]>;
806-
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
806+
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
807807
open(cacheName: string): Promise<Cache>;
808808
}
809809

@@ -2652,7 +2652,7 @@ interface Request extends Body {
26522652

26532653
declare var Request: {
26542654
prototype: Request;
2655-
new(input: RequestInfo, init?: RequestInit): Request;
2655+
new(input: RequestInfo | URL, init?: RequestInit): Request;
26562656
};
26572657

26582658
/** This Fetch API interface represents the response to a request. */
@@ -5128,7 +5128,7 @@ interface WindowOrWorkerGlobalScope {
51285128
clearTimeout(id?: number): void;
51295129
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
51305130
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
5131-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
5131+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
51325132
queueMicrotask(callback: VoidFunction): void;
51335133
reportError(e: any): void;
51345134
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
@@ -5498,7 +5498,7 @@ declare function clearInterval(id?: number): void;
54985498
declare function clearTimeout(id?: number): void;
54995499
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
55005500
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
5501-
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
5501+
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
55025502
declare function queueMicrotask(callback: VoidFunction): void;
55035503
declare function reportError(e: any): void;
55045504
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

baselines/sharedworker.generated.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,13 @@ declare var ByteLengthQueuingStrategy: {
753753
* Available only in secure contexts.
754754
*/
755755
interface Cache {
756-
add(request: RequestInfo): Promise<void>;
756+
add(request: RequestInfo | URL): Promise<void>;
757757
addAll(requests: RequestInfo[]): Promise<void>;
758-
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
759-
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
760-
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
761-
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
762-
put(request: RequestInfo, response: Response): Promise<void>;
758+
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
759+
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
760+
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
761+
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
762+
put(request: RequestInfo | URL, response: Response): Promise<void>;
763763
}
764764

765765
declare var Cache: {
@@ -775,7 +775,7 @@ interface CacheStorage {
775775
delete(cacheName: string): Promise<boolean>;
776776
has(cacheName: string): Promise<boolean>;
777777
keys(): Promise<string[]>;
778-
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
778+
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
779779
open(cacheName: string): Promise<Cache>;
780780
}
781781

@@ -2531,7 +2531,7 @@ interface Request extends Body {
25312531

25322532
declare var Request: {
25332533
prototype: Request;
2534-
new(input: RequestInfo, init?: RequestInit): Request;
2534+
new(input: RequestInfo | URL, init?: RequestInit): Request;
25352535
};
25362536

25372537
/** This Fetch API interface represents the response to a request. */
@@ -4982,7 +4982,7 @@ interface WindowOrWorkerGlobalScope {
49824982
clearTimeout(id?: number): void;
49834983
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
49844984
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
4985-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
4985+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
49864986
queueMicrotask(callback: VoidFunction): void;
49874987
reportError(e: any): void;
49884988
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
@@ -5514,7 +5514,7 @@ declare function clearInterval(id?: number): void;
55145514
declare function clearTimeout(id?: number): void;
55155515
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
55165516
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
5517-
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
5517+
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
55185518
declare function queueMicrotask(callback: VoidFunction): void;
55195519
declare function reportError(e: any): void;
55205520
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

baselines/webworker.generated.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ declare var ByteLengthQueuingStrategy: {
815815
* Available only in secure contexts.
816816
*/
817817
interface Cache {
818-
add(request: RequestInfo): Promise<void>;
818+
add(request: RequestInfo | URL): Promise<void>;
819819
addAll(requests: RequestInfo[]): Promise<void>;
820-
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
821-
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
822-
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
823-
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
824-
put(request: RequestInfo, response: Response): Promise<void>;
820+
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
821+
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
822+
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
823+
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
824+
put(request: RequestInfo | URL, response: Response): Promise<void>;
825825
}
826826

827827
declare var Cache: {
@@ -837,7 +837,7 @@ interface CacheStorage {
837837
delete(cacheName: string): Promise<boolean>;
838838
has(cacheName: string): Promise<boolean>;
839839
keys(): Promise<string[]>;
840-
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
840+
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
841841
open(cacheName: string): Promise<Cache>;
842842
}
843843

@@ -2750,7 +2750,7 @@ interface Request extends Body {
27502750

27512751
declare var Request: {
27522752
prototype: Request;
2753-
new(input: RequestInfo, init?: RequestInit): Request;
2753+
new(input: RequestInfo | URL, init?: RequestInit): Request;
27542754
};
27552755

27562756
/** This Fetch API interface represents the response to a request. */
@@ -5262,7 +5262,7 @@ interface WindowOrWorkerGlobalScope {
52625262
clearTimeout(id?: number): void;
52635263
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
52645264
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
5265-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
5265+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
52665266
queueMicrotask(callback: VoidFunction): void;
52675267
reportError(e: any): void;
52685268
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
@@ -5802,7 +5802,7 @@ declare function clearInterval(id?: number): void;
58025802
declare function clearTimeout(id?: number): void;
58035803
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
58045804
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
5805-
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
5805+
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
58065806
declare function queueMicrotask(callback: VoidFunction): void;
58075807
declare function reportError(e: any): void;
58085808
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

src/build/emitter.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,13 @@ export function emitWebIdl(
648648
}
649649
}
650650

651+
function acceptsUrl(p: Browser.Param) {
652+
return (
653+
(p.name.toLowerCase().includes("url") && p.type === "USVString") ||
654+
p.type === "RequestInfo"
655+
);
656+
}
657+
651658
function resolvePromise<T extends Browser.Typed>(t: T): T {
652659
const typedef =
653660
typeof t.type === "string" ? allTypedefsMap[t.type] : undefined;
@@ -672,7 +679,7 @@ export function emitWebIdl(
672679
function paramsToString(ps: Browser.Param[]) {
673680
function paramToString(p: Browser.Param) {
674681
p = resolvePromise(p);
675-
if (p.name.toLowerCase().includes("url") && p.type === "USVString") {
682+
if (acceptsUrl(p)) {
676683
p = { ...p, additionalTypes: [...(p.additionalTypes ?? [])] };
677684
p.additionalTypes!.push("URL");
678685
}

0 commit comments

Comments
 (0)