Skip to content

Commit

Permalink
Merge pull request #117 from Andarist/better-types
Browse files Browse the repository at this point in the history
Proper TS types
  • Loading branch information
developit authored Sep 29, 2020
2 parents 7d00e05 + 9f2ca62 commit aff2b9d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ declare namespace unfetch {
export type IsomorphicRequest = Request | NodeRequest
}

declare const unfetch: typeof fetch;
type UnfetchResponse = {
ok: boolean,
statusText: string,
status: number,
url: string,
text: () => Promise<string>,
json: () => Promise<any>,
blob: () => Promise<Blob>,
clone: () => UnfetchResponse,
headers: {
keys: () => string[],
entries: () => Array<[string, string]>,
get: (key: string) => string | undefined,
has: (key: string) => boolean,
}
}

type Unfetch = (
url: string,
options?: {
method?: string,
headers?: Record<string, string>,
credentials?: 'include' | 'omit',
body?: Parameters<XMLHttpRequest["send"]>[0]
}
) => Promise<UnfetchResponse>

declare const unfetch: Unfetch;

export default unfetch;

0 comments on commit aff2b9d

Please sign in to comment.