From 1c5652fc7b8c64ce9b9f5ce3153a1190ff2d411a Mon Sep 17 00:00:00 2001 From: Maxim Mazurok Date: Thu, 5 Jan 2023 12:28:17 +1100 Subject: [PATCH 1/2] allow to fetch URL --- @types/index.d.ts | 2 +- @types/index.test-d.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/@types/index.d.ts b/@types/index.d.ts index f68dd28e2..286fee5bf 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -145,7 +145,7 @@ export interface Body extends Pick {} export type RequestRedirect = 'error' | 'follow' | 'manual'; export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'; -export type RequestInfo = string | Request; +export type RequestInfo = string | URL | Request; export class Request extends BodyMixin { constructor(input: RequestInfo, init?: RequestInit); diff --git a/@types/index.test-d.ts b/@types/index.test-d.ts index 3272a0e7c..d75e0c5e5 100644 --- a/@types/index.test-d.ts +++ b/@types/index.test-d.ts @@ -7,6 +7,7 @@ import * as _fetch from '.'; async function run() { const getResponse = await fetch('https://bigfile.com/test.zip'); + await fetch(new URL('https://bigfile.com/test.zip')); expectType(getResponse.ok); expectType(getResponse.size); expectType(getResponse.status); From 802353c0f2f6e186e0fdb914d8183856477ae589 Mon Sep 17 00:00:00 2001 From: Maxim Mazurok Date: Fri, 6 Jan 2023 14:20:18 +1100 Subject: [PATCH 2/2] address comments --- @types/index.d.ts | 6 +++--- @types/index.test-d.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/@types/index.d.ts b/@types/index.d.ts index 286fee5bf..147a89b77 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -145,9 +145,9 @@ export interface Body extends Pick {} export type RequestRedirect = 'error' | 'follow' | 'manual'; export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'; -export type RequestInfo = string | URL | Request; +export type RequestInfo = string | Request; export class Request extends BodyMixin { - constructor(input: RequestInfo, init?: RequestInit); + constructor(input: RequestInfo | URL, init?: RequestInit); /** * Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. @@ -216,4 +216,4 @@ export class AbortError extends Error { } export function isRedirect(code: number): boolean; -export default function fetch(url: RequestInfo, init?: RequestInit): Promise; +export default function fetch(url: RequestInfo | URL, init?: RequestInit): Promise; diff --git a/@types/index.test-d.ts b/@types/index.test-d.ts index d75e0c5e5..d5b8b4004 100644 --- a/@types/index.test-d.ts +++ b/@types/index.test-d.ts @@ -37,6 +37,7 @@ async function run() { // Post try { const request = new Request('http://byjka.com/buka'); + new Request(new URL('http://byjka.com/buka')); expectType(request.url); expectType(request.headers);