Skip to content

Commit

Permalink
fix: make all createFetch options optional (resolves #266)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 22, 2023
1 parent bf3310c commit 55efdce
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
export interface CreateFetchOptions {
// eslint-disable-next-line no-use-before-define
defaults?: FetchOptions;
fetch: Fetch;
Headers: typeof Headers;
fetch?: Fetch;
Headers?: typeof Headers;
}

export type FetchRequest = RequestInfo;
Expand Down Expand Up @@ -86,8 +86,9 @@ const retryStatusCodes = new Set([
504, // Gateway Timeout
]);

export function createFetch(globalOptions: CreateFetchOptions): $Fetch {
const { fetch, Headers } = globalOptions;
export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
const { fetch = globalThis.fetch, Headers = globalThis.Headers } =
globalOptions;

async function onError(context: FetchContext): Promise<FetchResponse<any>> {
// Is Abort
Expand Down

0 comments on commit 55efdce

Please sign in to comment.