-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.d.ts
79 lines (68 loc) · 2.68 KB
/
fetch.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
declare type HeadersInit = Headers | string[][] | { [key: string]: string };
declare class Headers {
constructor(init?: HeadersInit);
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string; // | null; (TS 2.0 strict null check)
has(name: string): boolean;
set(name: string, value: string): void;
// WebIDL pair iterator: iterable<ByteString, ByteString>
entries(): IterableIterator<[string, string]>;
forEach(callback: (value: string, index: number, headers: Headers) => void, thisArg?: any): void;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<[string, string]>;
}
type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData | string;
interface Body {
bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<any>;
text(): Promise<string>;
}
declare type RequestInfo = string;
interface RequestInit {
method?: string;
headers?: HeadersInit;
body?: BodyInit;
referrer?: string;
referrerPolicy?: ReferrerPolicy;
mode?: RequestMode;
credentials?: RequestCredentials;
cache?: RequestCache;
redirect?: RequestRedirect;
integrity?: string;
window?: any;
}
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
type RequestDestination = "" | "document" | "embed" | "font" | "image" | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "worker" | "xslt";
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
type RequestCredentials = "omit" | "same-origin" | "include";
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
type RequestRedirect = "follow" | "error" | "manual";
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
declare class Response {
constructor(body?: BodyInit, init?: ResponseInit);
static error(): Response;
static redirect(url: string, status?: number): Response;
type: ResponseType;
url: string;
redirected: boolean;
status: number;
ok: boolean;
statusText: string;
headers: Headers;
body: any;
trailer: Promise<Headers>;
clone(): Response;
}
declare interface Response extends Body {}
interface ResponseInit {
status?: number;
statusText?: string;
headers?: HeadersInit;
}
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
export default function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;