Skip to content

Add URL to RequestInfo typedef #1269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3232,13 +3232,13 @@ declare var CSSTransition: {
* Available only in secure contexts.
*/
interface Cache {
add(request: RequestInfo): Promise<void>;
add(request: RequestInfo | URL): Promise<void>;
addAll(requests: RequestInfo[]): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to treat this one 🤔 but okay for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to properly implement this in generator either.
But in my opinion, even something like RequestInfo[] | URL[] would be an okay trade-off here: mixing those in userland code should be rarely needed.

Another option is to refactor this later by introducing some urlstring and RequestInfoOrUrl typedefs. Dunno about downsides.

These should be affected as well:

interface Cache {
addAll(requests: Iterable<RequestInfo>): Promise<void>;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmmmm. Let's merge this and tackle this in a separate patch.

delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo, response: Response): Promise<void>;
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo | URL, response: Response): Promise<void>;
}

declare var Cache: {
Expand All @@ -3254,7 +3254,7 @@ interface CacheStorage {
delete(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<string[]>;
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
open(cacheName: string): Promise<Cache>;
}

Expand Down Expand Up @@ -11229,7 +11229,7 @@ interface Request extends Body {

declare var Request: {
prototype: Request;
new(input: RequestInfo, init?: RequestInit): Request;
new(input: RequestInfo | URL, init?: RequestInit): Request;
};

interface ResizeObserver {
Expand Down Expand Up @@ -16453,7 +16453,7 @@ interface WindowOrWorkerGlobalScope {
clearTimeout(id?: number): void;
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
queueMicrotask(callback: VoidFunction): void;
reportError(e: any): void;
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down Expand Up @@ -17734,7 +17734,7 @@ declare function clearInterval(id?: number): void;
declare function clearTimeout(id?: number): void;
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
declare function queueMicrotask(callback: VoidFunction): void;
declare function reportError(e: any): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down
20 changes: 10 additions & 10 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,13 @@ declare var ByteLengthQueuingStrategy: {
* Available only in secure contexts.
*/
interface Cache {
add(request: RequestInfo): Promise<void>;
add(request: RequestInfo | URL): Promise<void>;
addAll(requests: RequestInfo[]): Promise<void>;
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo, response: Response): Promise<void>;
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo | URL, response: Response): Promise<void>;
}

declare var Cache: {
Expand All @@ -798,7 +798,7 @@ interface CacheStorage {
delete(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<string[]>;
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
open(cacheName: string): Promise<Cache>;
}

Expand Down Expand Up @@ -2632,7 +2632,7 @@ interface Request extends Body {

declare var Request: {
prototype: Request;
new(input: RequestInfo, init?: RequestInit): Request;
new(input: RequestInfo | URL, init?: RequestInit): Request;
};

/** This Fetch API interface represents the response to a request. */
Expand Down Expand Up @@ -5108,7 +5108,7 @@ interface WindowOrWorkerGlobalScope {
clearTimeout(id?: number): void;
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
queueMicrotask(callback: VoidFunction): void;
reportError(e: any): void;
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down Expand Up @@ -5477,7 +5477,7 @@ declare function clearInterval(id?: number): void;
declare function clearTimeout(id?: number): void;
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
declare function queueMicrotask(callback: VoidFunction): void;
declare function reportError(e: any): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down
20 changes: 10 additions & 10 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,13 @@ declare var ByteLengthQueuingStrategy: {
* Available only in secure contexts.
*/
interface Cache {
add(request: RequestInfo): Promise<void>;
add(request: RequestInfo | URL): Promise<void>;
addAll(requests: RequestInfo[]): Promise<void>;
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo, response: Response): Promise<void>;
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo | URL, response: Response): Promise<void>;
}

declare var Cache: {
Expand All @@ -770,7 +770,7 @@ interface CacheStorage {
delete(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<string[]>;
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
open(cacheName: string): Promise<Cache>;
}

Expand Down Expand Up @@ -2512,7 +2512,7 @@ interface Request extends Body {

declare var Request: {
prototype: Request;
new(input: RequestInfo, init?: RequestInit): Request;
new(input: RequestInfo | URL, init?: RequestInit): Request;
};

/** This Fetch API interface represents the response to a request. */
Expand Down Expand Up @@ -4963,7 +4963,7 @@ interface WindowOrWorkerGlobalScope {
clearTimeout(id?: number): void;
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
queueMicrotask(callback: VoidFunction): void;
reportError(e: any): void;
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down Expand Up @@ -5494,7 +5494,7 @@ declare function clearInterval(id?: number): void;
declare function clearTimeout(id?: number): void;
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
declare function queueMicrotask(callback: VoidFunction): void;
declare function reportError(e: any): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down
20 changes: 10 additions & 10 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,13 @@ declare var ByteLengthQueuingStrategy: {
* Available only in secure contexts.
*/
interface Cache {
add(request: RequestInfo): Promise<void>;
add(request: RequestInfo | URL): Promise<void>;
addAll(requests: RequestInfo[]): Promise<void>;
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo, response: Response): Promise<void>;
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
put(request: RequestInfo | URL, response: Response): Promise<void>;
}

declare var Cache: {
Expand All @@ -809,7 +809,7 @@ interface CacheStorage {
delete(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<string[]>;
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
match(request: RequestInfo | URL, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
open(cacheName: string): Promise<Cache>;
}

Expand Down Expand Up @@ -2684,7 +2684,7 @@ interface Request extends Body {

declare var Request: {
prototype: Request;
new(input: RequestInfo, init?: RequestInit): Request;
new(input: RequestInfo | URL, init?: RequestInit): Request;
};

/** This Fetch API interface represents the response to a request. */
Expand Down Expand Up @@ -5183,7 +5183,7 @@ interface WindowOrWorkerGlobalScope {
clearTimeout(id?: number): void;
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
queueMicrotask(callback: VoidFunction): void;
reportError(e: any): void;
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down Expand Up @@ -5722,7 +5722,7 @@ declare function clearInterval(id?: number): void;
declare function clearTimeout(id?: number): void;
declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
declare function queueMicrotask(callback: VoidFunction): void;
declare function reportError(e: any): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
Expand Down
5 changes: 4 additions & 1 deletion src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,10 @@ export function emitWebIdl(
function paramsToString(ps: Browser.Param[]) {
function paramToString(p: Browser.Param) {
p = resolvePromise(p);
if (p.name.toLowerCase().includes("url") && p.type === "USVString") {
if (
(p.name.toLowerCase().includes("url") && p.type === "USVString") ||
p.type === "RequestInfo"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a little bit long to be in a if clause, could you add a function for this and call it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

) {
p = { ...p, additionalTypes: [...(p.additionalTypes ?? [])] };
p.additionalTypes!.push("URL");
}
Expand Down