mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Reflect the latest Fetch API spec
This commit is contained in:
committed by
GitHub
parent
23c9f22309
commit
c610ec79c4
Vendored
+99
-92
@@ -1,98 +1,105 @@
|
||||
// Type definitions for fetch API
|
||||
// Type definitions for Fetch API
|
||||
// Project: https://github.com/github/fetch
|
||||
// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>
|
||||
// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>, Kagami Sascha Rosylight <https://github.com/saschanaz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Request extends Body {
|
||||
constructor(input: string|Request, init?:RequestInit);
|
||||
method: string;
|
||||
url: string;
|
||||
headers: Headers;
|
||||
context: RequestContext;
|
||||
referrer: string;
|
||||
mode: RequestMode;
|
||||
redirect: RequestRedirect;
|
||||
credentials: RequestCredentials;
|
||||
cache: RequestCache;
|
||||
}
|
||||
|
||||
interface RequestInit {
|
||||
method?: string;
|
||||
headers?: HeaderInit|{ [index: string]: string };
|
||||
body?: BodyInit;
|
||||
mode?: RequestMode;
|
||||
redirect?: RequestRedirect;
|
||||
credentials?: RequestCredentials;
|
||||
cache?: RequestCache;
|
||||
}
|
||||
|
||||
type RequestContext =
|
||||
"audio" | "beacon" | "cspreport" | "download" | "embed" |
|
||||
"eventsource" | "favicon" | "fetch" | "font" | "form" | "frame" |
|
||||
"hyperlink" | "iframe" | "image" | "imageset" | "import" |
|
||||
"internal" | "location" | "manifest" | "object" | "ping" | "plugin" |
|
||||
"prefetch" | "script" | "serviceworker" | "sharedworker" |
|
||||
"subresource" | "style" | "track" | "video" | "worker" |
|
||||
"xmlhttprequest" | "xslt";
|
||||
type RequestMode = "same-origin" | "no-cors" | "cors";
|
||||
type RequestRedirect = "follow" | "error" | "manual";
|
||||
type RequestCredentials = "omit" | "same-origin" | "include";
|
||||
type RequestCache =
|
||||
"default" | "no-store" | "reload" | "no-cache" |
|
||||
"force-cache" | "only-if-cached";
|
||||
|
||||
declare interface HeadersMap {
|
||||
[index: string]: string;
|
||||
}
|
||||
|
||||
declare class Headers {
|
||||
constructor(headers?:Headers|HeadersMap)
|
||||
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;
|
||||
forEach(callback: (value: string, name: string) => void): void;
|
||||
}
|
||||
|
||||
declare class Body {
|
||||
bodyUsed: boolean;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
blob(): Promise<Blob>;
|
||||
formData(): Promise<FormData>;
|
||||
json(): Promise<any>;
|
||||
json<T>(): Promise<T>;
|
||||
text(): Promise<string>;
|
||||
}
|
||||
|
||||
declare class Response extends Body {
|
||||
constructor(body?: BodyInit, init?: ResponseInit);
|
||||
static error(): Response;
|
||||
static redirect(url: string, status: number): Response;
|
||||
type: ResponseType;
|
||||
url: string;
|
||||
status: number;
|
||||
ok: boolean;
|
||||
statusText: string;
|
||||
headers: Headers;
|
||||
clone(): Response;
|
||||
}
|
||||
|
||||
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
|
||||
|
||||
interface ResponseInit {
|
||||
status: number;
|
||||
statusText?: string;
|
||||
headers?: HeaderInit;
|
||||
}
|
||||
|
||||
declare type HeaderInit = Headers|Array<string>;
|
||||
declare type BodyInit = ArrayBuffer|ArrayBufferView|Blob|FormData|string;
|
||||
declare type RequestInfo = Request|string;
|
||||
|
||||
interface Window {
|
||||
fetch(url: string|Request, init?: RequestInit): Promise<Response>;
|
||||
fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
declare var fetch: typeof window.fetch;
|
||||
|
||||
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;
|
||||
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]>;
|
||||
}
|
||||
|
||||
declare var fetch: typeof window.fetch;
|
||||
declare type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData /* | URLSearchParams */ | string;
|
||||
interface Body {
|
||||
bodyUsed: boolean;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
blob(): Promise<Blob>;
|
||||
formData(): Promise<FormData>;
|
||||
json(): Promise<any>;
|
||||
text(): Promise<string>;
|
||||
}
|
||||
|
||||
declare type RequestInfo = Request | string;
|
||||
interface Request extends Body {
|
||||
method: string;
|
||||
url: string;
|
||||
headers: Headers;
|
||||
|
||||
type: "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
|
||||
destination: "" | "document" | "embed" | "font" | "image" | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "worker" | "xslt";
|
||||
referrer: string;
|
||||
referrerPolicy: ReferrerPolicy;
|
||||
mode: RequestMode;
|
||||
credentials: RequestCredentials;
|
||||
cache: RequestCache;
|
||||
redirect: RequestRedirect;
|
||||
integrity: string;
|
||||
|
||||
clone(): Request;
|
||||
}
|
||||
interface RequestInit {
|
||||
method?: string;
|
||||
headers?: HeadersInit;
|
||||
body?: BodyInit;
|
||||
referrer?: string;
|
||||
referrerPolicy?: ReferrerPolicy;
|
||||
mode?: RequestMode;
|
||||
credentials?: RequestCredentials;
|
||||
cache?: RequestCache;
|
||||
redirect?: RequestRedirect;
|
||||
integrity?: string;
|
||||
window?: any;
|
||||
}
|
||||
interface RequestConstructor {
|
||||
new (input: RequestInfo, init?: RequestInit): Request;
|
||||
}
|
||||
declare var Request: RequestConstructor;
|
||||
|
||||
type RequestMode = "same-origin" | "no-cors" | "cors";
|
||||
type RequestCredentials = "omit" | "same-origin" | "include";
|
||||
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache";
|
||||
type RequestRedirect = "follow" | "error" | "manual";
|
||||
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "unsafe-url";
|
||||
|
||||
interface Response extends Body {
|
||||
type: "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
|
||||
url: string;
|
||||
redirected: boolean;
|
||||
status: number;
|
||||
ok: boolean;
|
||||
statusText: string;
|
||||
headers: Headers;
|
||||
body: any /*ReadableStream | null*/;
|
||||
trailer: Promise<Headers>;
|
||||
|
||||
clone(): Response;
|
||||
}
|
||||
interface ResponseInit {
|
||||
status?: number;
|
||||
statusText?: number;
|
||||
headers?: HeadersInit;
|
||||
}
|
||||
interface ResponseConstructor {
|
||||
new (body?: BodyInit, init?: ResponseInit): Response;
|
||||
|
||||
error(): Response;
|
||||
redirect(url: string, status?: number): Response;
|
||||
}
|
||||
declare var Response: ResponseConstructor;
|
||||
|
||||
Reference in New Issue
Block a user