Skip to content

Commit e093030

Browse files
Allow URL class object as an argument for fetch() (#1696)
* allow to fetch URL * address comments
1 parent 55a4870 commit e093030

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

@types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export type RequestRedirect = 'error' | 'follow' | 'manual';
147147
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';
148148
export type RequestInfo = string | Request;
149149
export class Request extends BodyMixin {
150-
constructor(input: RequestInfo, init?: RequestInit);
150+
constructor(input: RequestInfo | URL, init?: RequestInit);
151151

152152
/**
153153
* 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 {
216216
}
217217

218218
export function isRedirect(code: number): boolean;
219-
export default function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
219+
export default function fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response>;

@types/index.test-d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as _fetch from '.';
77

88
async function run() {
99
const getResponse = await fetch('https://bigfile.com/test.zip');
10+
await fetch(new URL('https://bigfile.com/test.zip'));
1011
expectType<boolean>(getResponse.ok);
1112
expectType<number>(getResponse.size);
1213
expectType<number>(getResponse.status);
@@ -36,6 +37,7 @@ async function run() {
3637
// Post
3738
try {
3839
const request = new Request('http://byjka.com/buka');
40+
new Request(new URL('http://byjka.com/buka'));
3941
expectType<string>(request.url);
4042
expectType<Headers>(request.headers);
4143

0 commit comments

Comments
 (0)