Skip to content

Commit

Permalink
Allow URL class object as an argument for fetch() (#1696)
Browse files Browse the repository at this point in the history
* allow to fetch URL

* address comments
  • Loading branch information
Maxim-Mazurok committed Jan 9, 2023
1 parent 55a4870 commit e093030
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions @types/index.d.ts
Expand Up @@ -147,7 +147,7 @@ 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 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.
Expand Down Expand Up @@ -216,4 +216,4 @@ export class AbortError extends Error {
}

export function isRedirect(code: number): boolean;
export default function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
export default function fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response>;
2 changes: 2 additions & 0 deletions @types/index.test-d.ts
Expand Up @@ -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<boolean>(getResponse.ok);
expectType<number>(getResponse.size);
expectType<number>(getResponse.status);
Expand Down Expand Up @@ -36,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<string>(request.url);
expectType<Headers>(request.headers);

Expand Down

0 comments on commit e093030

Please sign in to comment.