Skip to content
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

[Types] Type of header in AxiosRequestConfig / for Axios.create is incorrect #4911

Closed
ghost91- opened this issue Aug 11, 2022 · 1 comment
Closed

Comments

@ghost91-
Copy link

Describe the bug

This is a follow up to #4184, as the problem still exists in version 1.0.0-alpha.1.

More concretely, The type of the headers property in Axios.create config doesn't support headers for specific requests method (or common).

To Reproduce

const axiosRequestConfig: AxiosRequestConfig = {
    headers: {
        get: { 'Accept-Language': 'en' } // same with common, or other http methods
    }
};

Axios.create(axiosRequestConfig);

results in the error

Type '{ get: { 'Accept-Language': string; }; }' is not assignable to type 'Partial<AxiosHeaders & MethodsHeaders & CommonHeaders>'.
  Property 'get' is incompatible with index signature.
    Type '{ 'Accept-Language': string; }' is not assignable to type 'string | number | boolean | string[] | undefined'.
      Object literal may only specify known properties, and ''Accept-Language'' does not exist in type 'string[]'.ts(2322)

Expected behavior

The above code example type checks successfully.

Environment

  • Axios Version 1.0.0-alpha.1

Additional context/Screenshots

Related issues: #4184, #4193

WillianAgostini added a commit to WillianAgostini/axios that referenced this issue Aug 21, 2022
The type of the headers property in Axios.create config has not support
headers for specific requests method (or common).

Closes axios#4911
@WillianAgostini
Copy link
Contributor

WillianAgostini commented Aug 21, 2022

Open PR #4927

WillianAgostini added a commit to WillianAgostini/axios that referenced this issue Aug 21, 2022
The type of the headers property in Axios.create config has not support
headers for specific requests method (or common).

Closes axios#4911
WillianAgostini added a commit to WillianAgostini/axios that referenced this issue Aug 21, 2022
Type of header in AxiosRequestConfig / for Axios.create is incorrect
WillianAgostini added a commit to WillianAgostini/axios that referenced this issue Aug 21, 2022
Add new type for MethodsHeaders in AxiosRequestHeaders

Closes axios#4911
jasonsaayman added a commit that referenced this issue Sep 28, 2022
…is incorrect (#4927)

* test: Fail test to #4911

Type of header in AxiosRequestConfig / for Axios.create is incorrect

* fix: Type of header in AxiosRequestConfig is incorrect

Add new type for MethodsHeaders in AxiosRequestHeaders

Closes #4911

* refactor: Remove interface to add type #4927

Co-authored-by: Jay <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants