Describe the bug
Hello!
The types for response.headers is an object with Title Case keys:
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
AxiosResponse<any, any>.headers: AxiosResponseHeaders | Partial<RawAxiosHeaders & {
Server: AxiosHeaderValue;
"Content-Type": AxiosHeaderValue;
"Content-Length": AxiosHeaderValue;
"Cache-Control": AxiosHeaderValue;
"Content-Encoding": AxiosHeaderValue;
} & {
...;
}>
However, the actual object has lowercase keys, and this is consistent with the documentation:
// `headers` the HTTP headers that the server responded with
// All header names are lower cased and can be accessed using the bracket notation.
// Example: `response.headers['content-type']`
headers: {},
To Reproduce
const response = await axios.head(url);
// typed as any, but has a value
const lowercase = response.headers['content-length'];
// correctly typed, but has an undefined value
const titlecase = response.headers['Content-Length'];
In this case, the lowercase type is any and the titlecase type is AxiosHeaderValue | undefined. However, lowercase has the correct value, and titlecase is undefined.
I think this just needs a Lowercase added to the keys of the response type? Should CommonResponseHeadersList all be lower-cased?
Expected behavior
The key types for the response headers should match the actual keys that Axios converts to lowercase.
Sandbox link
https://codesandbox.io/p/sandbox/agitated-sound-9tj77c
Axios version
1.7.7
Node.js Version
20
OS
React Native, but this is a TypeScript thing!
Additional Library Versions
Describe the bug
Hello!
The types for
response.headersis an object with Title Case keys:However, the actual object has lowercase keys, and this is consistent with the documentation:
To Reproduce
In this case, the
lowercasetype isanyand thetitlecasetype isAxiosHeaderValue | undefined. However,lowercasehas the correct value, andtitlecaseis undefined.I think this just needs a
Lowercaseadded to the keys of the response type? ShouldCommonResponseHeadersListall be lower-cased?Expected behavior
The key types for the response headers should match the actual keys that Axios converts to lowercase.
Sandbox link
https://codesandbox.io/p/sandbox/agitated-sound-9tj77c
Axios version
1.7.7
Node.js Version
20
OS
React Native, but this is a TypeScript thing!
Additional Library Versions