forked from ryan-codingintrigue/typescript-fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js.d.ts
60 lines (54 loc) · 1.56 KB
/
fetch.js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Type definitions for fetch API
// Spec: https://fetch.spec.whatwg.org/
// Polyfill: https://github.com/github/fetch
// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>
interface FetchOptions {
method?: "GET" | "POST" | "DELETE" | "PATCH" | "PUT" | "HEAD" | "OPTIONS" | "CONNECT";
headers?: any;
body?: any;
mode?: "cors" | "no-cors" | "same-origin";
credentials?: "omit" | "same-origin" | "include";
cache?: "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
redirect?: "follow" | "error" | "manual";
referrer?: string;
referrerPolicy?: "referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "unsafe-url";
integrity?: any;
}
declare enum ResponseType {
Basic,
Cors,
Default,
Error,
Opaque
}
interface Headers {
append(name: string, value: string):void;
delete(name: string):void;
get(name: string): string;
getAll(name: string): Array<string>;
has(name: string): boolean;
set(name: string, value: string): void;
}
interface Body {
bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<JSON>;
text(): Promise<string>;
}
interface Response extends Body {
error(): Response;
redirect(url: string, status?: number): Response;
type: ResponseType;
url: string;
status: number;
ok: boolean;
statusText: string;
headers: Headers;
clone(): Response;
}
interface Window {
fetch(url: string): Promise<Response>;
fetch(url: string, options: FetchOptions): Promise<Response>;
}