New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix response headers types #4136
Conversation
some keys like 'set-cookie' are arrays https://github.com/axios/axios/blob/master/lib/helpers/parseHeaders.js#L45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably make sense to introduce a specifc AxiosHeaders
type:
type AxiosHeaders = Record<Exclude<"set-cookie", string>, string> & {
"set-cookie"?: string[]
}
Note that it is also used in the AxiosTransformer
and AxiosRequestConfig
interfaces:
Lines 1 to 3 in 6c00232
export interface AxiosTransformer { | |
(data: any, headers?: Record<string, string>): any; | |
} |
Lines 50 to 56 in 6c00232
export interface AxiosRequestConfig<D = any> { | |
url?: string; | |
method?: Method; | |
baseURL?: string; | |
transformRequest?: AxiosTransformer | AxiosTransformer[]; | |
transformResponse?: AxiosTransformer | AxiosTransformer[]; | |
headers?: Record<string, string>; |
You might want to wait until #4140 is merged, because it adds a new |
👍 for differentiating The common ground would be to keep |
Haha sorry – I was referring to that PR assigning things to type aliases, I should have clarified that! Was sharing that the two PRs could build from one another 😄 |
Actually, #4117 was the first PR to suggest adding a |
I like this idea! But it doesn’t work. After some fiddling I came up with: type AxiosHeaders = Record<string, string> & {
"set-cookie"?: string[]
} Also we may want to differentiate between request and response headers, as type AxiosRequestHeaders = Record<string, string>;
type AxiosResponseHeaders = Record<string, string> & {
"set-cookie"?: string[]
}; |
…ster # Conflicts: # index.d.ts
I have a question about this code, |
@EyebrowsWhite Not sure why it doesn't work when declaring the header object directly, but the following works (see playground): type AxiosHeaders = Record<string, string> & {
"set-cookie"?: string[]
}
declare let headers: AxiosHeaders;
headers = {}
headers['Content-Type'] = 'text/plain'
headers['set-cookie'] = ['abc', 'def'] |
* fix response headers types some keys like 'set-cookie' are arrays https://github.com/axios/axios/blob/master/lib/helpers/parseHeaders.js#L45 * split header types
some keys like 'set-cookie' are arrays https://github.com/axios/axios/blob/master/lib/helpers/parseHeaders.js#L45