Skip to content

axios 1.2.3 causes an AxiosHeader error #5476

Closed

Description

@laterdayi

Describe the bug

axios 1.2.3 causes an AxiosHeader error

The type {Token: string; Refresh: string; } "to type" AxiosRequestHeaders ".

Type "{Token: string; Refresh: string; } "Missing the following properties for type" AxiosHeaders ": set, get, has, delete and 19 others

Type "{params: {LayoutId: (string | number | null) []; check: string; }; } "cannot be assigned to an argument of type" AxiosRequestConfig ".

Type {params: {" LayoutId: (string | number | null) []; check: string; }; The attribute "headers" is missing from "}", but is required for type "AxiosRequestConfig"

To Reproduce

No response

Code snippet

No response

Expected behavior

No response

Axios Version

No response

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

Activity

  1. laterdayi commented on Jan 18, 2023

    @laterdayi
    Author

    in 1.2.2 ,it work

  2. laterdayi commented on Jan 18, 2023

    @laterdayi
    Author

    herader is not required to use it

  3. alecgibson commented on Jan 18, 2023

    @alecgibson

    I think this was a type-breaking change introduced in #5420

    You now need to replace usage of AxiosRequestConfig with RawAxiosRequestConfig.

  4. tada5hi commented on Jan 18, 2023

    @tada5hi

    TS2741: Property 'headers' is missing in type '{ proxy: false; }' but required in type 'ClientRequestConfig<any>'.

  5. tada5hi commented on Jan 18, 2023

    @tada5hi

    follow up issue of #5416

  6. laterdayi commented on Jan 18, 2023

    @laterdayi
    Author

    such as

     import type { AxiosRequestConfig } from 'axios';
    
     function execute(queryParams: ExportParamsType | object, config?: AxiosRequestConfig): Promise<void>;
    

    This means that all types that use AxiosRequestConfig need to be replaced All with RawAxiosRequestConfig ?

    @tada5hi @alecgibson

  7. tada5hi commented on Jan 18, 2023

    @tada5hi

    @laterdayi yep, because the headers property is mandatory in the AxiosRequestConfig type. Another option would be to create an AxiosHeader instance instead switching the type.

    But I'm not sure if the behaviour changes again in an upcoming release :person_shrugging:

  8. laterdayi commented on Jan 18, 2023

    @laterdayi
    Author

    @tada5hi The current solution is to change everything you use with AxiosRequestConfig to RawAxiosRequestConfig, right?

  9. tada5hi commented on Jan 18, 2023

    @tada5hi

    @laterdayi Taking into account the current version, yes.

    This should also avoid the following generic bug: #5478

  10. laterdayi commented on Jan 18, 2023

    @laterdayi
    Author

    @tada5hi Expect the next release to fix this

  11. arthurfiorette commented on Jan 18, 2023

    @arthurfiorette
    Contributor

    Another problem here is that you cannot create, with valid typescript, a instance of AxiosRequestHeaders.

    // Type '{}' is missing the following properties from type
    // 'AxiosHeaders': set, get, has, delete, and 19 more.
    const headers: AxiosRequestHeaders = {};
    
    // Type 'AxiosHeaders' is not assignable to type 
    // 'Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>'
    const headers: AxiosRequestHeaders = new AxiosHeaders();
  12. bombillazo commented on Jan 19, 2023

    @bombillazo

    Im getting this error when setting headers inline:
    image

  13. VGalata commented on Jan 19, 2023

    @VGalata

    AxiosResponse is also affected by the introduced breaking change as it has config: AxiosRequestConfig<D> (see here in code).

  14. FrankEssenberger commented on Jan 19, 2023

    @FrankEssenberger

    The PR #5420 ontroduced a breaking API change in a patch versin release 1.2.3. This also broke our pipeline. As mentioned replacing AxiosRequestConfig with RawAxiosRequestConfig solves the issue. However, it would be great if you could be more careful in the future. If you look at the changes adding a mandatory field headers is obviously not type compatible in structural typing. So you should use assertions/checks in version 1.X.Y and make it mandatory in version 2.X.Y.

  15. bombillazo commented on Jan 19, 2023

    @bombillazo

    You now need to replace usage of AxiosRequestConfig with RawAxiosRequestConfig.

    As mentioned replacing AxiosRequestConfig with RawAxiosRequestConfig solves the issue.

    Can confirm this works for us! 🙌

  16. 6 remaining items

  17. DigitalBrainJS commented on Jan 19, 2023

    @DigitalBrainJS
    Collaborator

    @jameyg42 Definitely should, however, it is not always possible to make a fix for one thing without any impact on another. It seems that no matter what solution we choose here, the consequences cannot be completely avoided. The only question is where they will appear and how significantly they will affect.

  18. bombillazo commented on Jan 19, 2023

    @bombillazo

    What about the prefix Custom?

    To me, Raw sounds like some type that is used internally by Axios and has not been sanitized/transformed to make it usable by others.

  19. added a commit that references this issue on Jan 19, 2023
  20. DigitalBrainJS commented on Jan 20, 2023

    @DigitalBrainJS
    Collaborator

    So it seems there are three options:

    1. leave the update as is:
      External (user) config - RawAxiosConfig
      Internal - AxiosConfig
    2. partial rollback with an alias (probably until the next major release):
      External (user) config - AxiosConfig = RawAxiosConfig (alias)
      Internal - InternalAxiosConfig
    3. partial rollback forever
      External (user) config - AxiosConfig
      Internal - InternalAxiosConfig

    Any suggestions are welcome.

  21. arthurfiorette commented on Jan 20, 2023

    @arthurfiorette
    Contributor

    Can we use 3 until next big release?

  22. rcoundon commented on Jan 20, 2023

    @rcoundon

    So it seems there are three options:

    1. leave the update as is:
      External (user) config - RawAxiosConfig
      Internal - AxiosConfig
    2. partial rollback with an alias (probably until the next major release):
      External (user) config - AxiosConfig = RawAxiosConfig (alias)
      Internal - InternalAxiosConfig
    3. partial rollback forever
      External (user) config - AxiosConfig
      Internal - InternalAxiosConfig

    Any suggestions are welcome.

    I don't think 1 is quite right - see #5476 (comment)

  23. DigitalBrainJS commented on Jan 20, 2023

    @DigitalBrainJS
    Collaborator

    @rcoundon that was another issue due to a missing generic parameter in the interface declaration. This has been fixed in the codebase with #5478.

  24. DigitalBrainJS commented on Jan 20, 2023

    @DigitalBrainJS
    Collaborator

    @arthurfiorette If we are still going to rename the interface in the next major version, then the 2nd option could be preferable since users who have already changed the interface's name will not be forced to rename it back. I don't think they'll be thrilled about it :) Of course, it depends on whether users use the updated AxiosConfig interface somewhere as an internal config or not. We need to think carefully about this step.

  25. rcoundon commented on Jan 20, 2023

    @rcoundon

    @rcoundon that was another issue due to a missing generic parameter in the interface declaration. This has been fixed in the codebase with #5478.

    Ok - thanks for clarifying

  26. JoseLion commented on Jan 21, 2023

    @JoseLion

    I believe option 2 is the best approach at this point. We'll keep the fix introduced by #5420 to solve issue #5415 while leaving the interface name as before. Still a (relatively) small breaking change because of the required prop, but users won't have to change AxiosConfig to RawAxiosConfig everywhere. It seems like a good compromise between all circumstances to me 🙂

  27. JoseLion commented on Jan 21, 2023

    @JoseLion

    Another problem here is that you cannot create, with valid typescript, a instance of AxiosRequestHeaders.

    // Type '{}' is missing the following properties from type
    // 'AxiosHeaders': set, get, has, delete, and 19 more.
    const headers: AxiosRequestHeaders = {};
    
    // Type 'AxiosHeaders' is not assignable to type 
    // 'Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>'
    const headers: AxiosRequestHeaders = new AxiosHeaders();

    This is another big piece to consider, though 🤔

  28. nfantone commented on Jan 31, 2023

    @nfantone

    1.2.6 is also affected. Last healthy version seems to be 1.2.2 as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions