Skip to content

Commit aff2b9d

Browse files
authored
Merge pull request #117 from Andarist/better-types
Proper TS types
2 parents 7d00e05 + 9f2ca62 commit aff2b9d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/index.d.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ declare namespace unfetch {
1212
export type IsomorphicRequest = Request | NodeRequest
1313
}
1414

15-
declare const unfetch: typeof fetch;
15+
type UnfetchResponse = {
16+
ok: boolean,
17+
statusText: string,
18+
status: number,
19+
url: string,
20+
text: () => Promise<string>,
21+
json: () => Promise<any>,
22+
blob: () => Promise<Blob>,
23+
clone: () => UnfetchResponse,
24+
headers: {
25+
keys: () => string[],
26+
entries: () => Array<[string, string]>,
27+
get: (key: string) => string | undefined,
28+
has: (key: string) => boolean,
29+
}
30+
}
31+
32+
type Unfetch = (
33+
url: string,
34+
options?: {
35+
method?: string,
36+
headers?: Record<string, string>,
37+
credentials?: 'include' | 'omit',
38+
body?: Parameters<XMLHttpRequest["send"]>[0]
39+
}
40+
) => Promise<UnfetchResponse>
41+
42+
declare const unfetch: Unfetch;
1643

1744
export default unfetch;

0 commit comments

Comments
 (0)