You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Axios response headers can actually be undefined. For instance, a response can sometimes contain the location header, and sometimes not.
To Reproduce
typeExpense={// ...};asyncfunctionpostExpense(projectId: string,expense: Omit<Expense,'id'>): Promise<string>{constres=awaitaxios.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 oneconstlocation=res.headers.location;// this causes this variable to be `undefined`, and leads to errors when the function is calledreturnlocation;}
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
The text was updated successfully, but these errors were encountered:
gprst
changed the title
Axios response headers can be undefined (TS typing isn't strict enough)
Axios response headers can be undefined (TS typing isn't strict enough)
Jun 25, 2022
The response headers were always available in previous versions. Is the expectation that response headers should be checked for undefined, or is this a recent breaking change?
I don't know about the history of the codebase. I just know that currently, you can get a value that'd be typed as string, although it could actually be undefined — so yes, the expectation is that response headers should be typed as string | undefined, to be more accurate.
Describe the bug
Axios response headers can actually be
undefined
. For instance, a response can sometimes contain thelocation
header, and sometimes not.To Reproduce
Expected behavior
AxiosResponseHeaders
should reflect the fact that headers can beundefined
.Environment
Additional context/Screenshots
N/A
The text was updated successfully, but these errors were encountered: