Describe the bug
Axios response headers can actually be undefined. For instance, a response can sometimes contain the location header, and sometimes not.
To Reproduce
type Expense = {
// ...
};
async function postExpense(projectId: string, expense: Omit<Expense, 'id'>): Promise<string> {
const res = await axios.post(`/projects/${projectId}/expenses`, expense);
// `res.headers.location` is considered as a string, even though it could be `undefined`
// e.g. when the response from the server is an error one
const location = res.headers.location;
// this causes this variable to be `undefined`, and leads to errors when the function is called
return location;
}
Expected behavior
AxiosResponseHeaders should reflect the fact that headers can be undefined.
Environment
- Axios Version: 0.27.2
- Adapter: N/A
- Browser: N/A
- Browser Version: N/A
- Node.js Version: 16.15.1
- OS: N/A
- Additional Library Versions: N/A
Additional context/Screenshots
N/A
Describe the bug
Axios response headers can actually be
undefined. For instance, a response can sometimes contain thelocationheader, and sometimes not.To Reproduce
Expected behavior
AxiosResponseHeadersshould reflect the fact that headers can beundefined.Environment
Additional context/Screenshots
N/A