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:
Ken Sheedlo 2015-04-05 19:46:19 -07:00
parent 2520bce9a8
commit a3a294fb4f
2 changed files with 13 additions and 3 deletions

View File

@ -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);
});
}
}

View File

@ -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>;
}
}