From b733dcefe8120a1be9926e3c4126a3aa21ed1e19 Mon Sep 17 00:00:00 2001 From: Diogo Franco Date: Mon, 28 Nov 2016 13:02:33 +0900 Subject: [PATCH 1/2] Better typing for headers Lack of indexing in `AxiosXHR#headers` made it unusable without casting. Requests / Responses with more than one instance of the same header make the value be a `string[]`. Often happens with headers like `Set-Cookie`. --- axios/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axios/index.d.ts b/axios/index.d.ts index a2c5bfbd45..d66dc3d48c 100644 --- a/axios/index.d.ts +++ b/axios/index.d.ts @@ -159,7 +159,7 @@ declare namespace Axios { /** * headers that the server responded with */ - headers: Object; + headers: {[index: string]: any}; /** * config that was provided to `axios` for the request From ae053e2298ab1f9195529cbc8c867f7e653c8e33 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Mon, 28 Nov 2016 13:22:35 +0900 Subject: [PATCH 2/2] Add test for headers change --- axios/axios-tests.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/axios/axios-tests.ts b/axios/axios-tests.ts index a321e97f19..eb98e2710c 100644 --- a/axios/axios-tests.ts +++ b/axios/axios-tests.ts @@ -80,7 +80,11 @@ var axiosInstance = axios.create({ timeout: 1000 }); -axiosInstance.request({url: "issues/1"}); +axiosInstance.request({url: "issues/1"}).then(res => { + if (res.headers['content-type'].startsWith('application/json')) { + throw new Error('Unexpected content-type'); + } +}); axios.all([getRepoDetails, getRepoDetails]).then(([repo1, repo2]) => { var sumIds = repo1.data.id + repo2.data.id;