axios: Types are still broken with 1.2.4 for interceptors
Describe the bug
Assigning custom interceptors that accept and return AxiosRequestConfig
works with 1.2.2, but breaks with 1.2.4.
This is used by e.g. https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/axios-token-interceptor, and also in user code.
Code snippet
axios.interceptors.request.use((config: AxiosRequestConfig) => Promise.resolve(config));
Error message
error TS2345: Argument of type '(config: AxiosRequestConfig) => Promise<AxiosRequestConfig<any>>' is not assignable to parameter of type '(value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
Type 'Promise<AxiosRequestConfig<any>>' is not assignable to type 'InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
150 axios.interceptors.request.use((config: AxiosRequestConfig) => Promise.resolve(config));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Expected behavior
It should not break, this is a minor upgrade.
### Axios Version
1.2.4
### Adapter Version
_No response_
### Browser
_No response_
### Browser Version
_No response_
### Node.js Version
18.12.1
### OS
_No response_
### Additional Library Versions
```bash
Typescript
Additional context/Screenshots
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 24
- Comments: 22
Commits related to this issue
- [feat] creating axios request interceptor — committed to Be-log/be-log by hansololiviakim 10 months ago
- temp fix: use InternalAxiosRequestConfig instead of AxiosRequestConfig see https://github.com/axios/axios/issues/5494 or https://github.com/axios/axios/issues/5573 — committed to woocommerce/woocommerce by lsinger 7 months ago
Config inside interceptors has a different interface. If you explicitly specify the config type, use
InternalAxiosRequestConfig
instead ofAxiosRequestConfig
.AxiosRequestConfig
is the external/raw config interface.Try this
Can confirm after 1.2.2 is breaking change for typescript users.
Still not working with TS after v1.4.0
you can just downgrade your Axios version = “axios”: “^0.24.0” … it’s working fine
The interceptor signature seems to have changed, fix by using
header.set( .. , .. )
worksOn Tue, 21 Mar 2023 at 13:36, YR @.***> wrote:
– Kwasi Owusu Gyasi-Agyei @.*** \ +27 (81) 466 - 4488
Until this is fixed, I added
as any
where needed…Also not working with Axios v1.5.0 I am afraid.
Still broken version axios version 1.3.4
I already mentioned it in #5476 for
1.2.3
(see here) and the problem still persists in version1.2.4
: theheaders
of theconfig
inAxiosResponse
are not optional anymore (as it was in1.2.1
). In1.2.4
, the config has the typeInternalAxiosRequestConfig
(in code) which is still a breaking change. It affects then also the interceptors as described in the first post.Most likely though this package is deprecated as it depends on Axios 0.x.
The incompatibility is only in the TypeScript types.
Still broken version axios version 1.3.3
@DigitalBrainJS it’s harder than I expected. Pushed my changes to https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64075, but the test fails.
This is the test:
and this is the error: