-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Axios response headers can be undefined (TS typing isn't strict enough) #4812
Copy link
Copy link
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels