mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add support for headers as object in whatwg-fetch
The current typing supports passing headers through the Headers class, but the spec also supports passing headers as an object mapping header names to header values. See the [Github example](https://github.com/github/fetch#post-json).
This commit is contained in:
parent
2520bce9a8
commit
a3a294fb4f
@ -11,6 +11,16 @@ function test_fetchUrlWithOptions() {
|
||||
handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php", requestOptions));
|
||||
}
|
||||
|
||||
function test_fetchUrlWithHeadersObject() {
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php", requestOptions));
|
||||
}
|
||||
|
||||
function test_fetchUrl() {
|
||||
handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php"));
|
||||
}
|
||||
@ -21,4 +31,4 @@ function handlePromise(promise: Promise<Response>) {
|
||||
}).then((text) => {
|
||||
console.log(text);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
4
whatwg-fetch/whatwg-fetch.d.ts
vendored
4
whatwg-fetch/whatwg-fetch.d.ts
vendored
@ -19,7 +19,7 @@ declare class Request {
|
||||
|
||||
interface RequestInit {
|
||||
method?: string;
|
||||
headers?: HeaderInit;
|
||||
headers?: HeaderInit|{ [index: string]: string };
|
||||
body?: BodyInit;
|
||||
mode?: RequestMode;
|
||||
credentials?: RequestCredentials;
|
||||
@ -81,4 +81,4 @@ declare type RequestInfo = Request|string;
|
||||
|
||||
interface Window {
|
||||
fetch(url: string, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user