im using React and axios, recently i have created a custom config on axios like this:
import $axios from 'helpers/axiosInstance'
$axios.get('/customers', { handlerEnabled: false })
but the result ts compilation:
Argument of type '{ handlerEnabled: boolean; }' is not assignable to parameter of type 'AxiosRequestConfig'. Object literal may only specify known properties, and 'handlerEnabled' does not exist in type 'AxiosRequestConfig'.
how can i assign new types on AxiosRequestConfig?
something like this axios<AxiosRequestConfig & newType>
dont wanna use old method like .d.ts
You can extend any library types, by using the typescript decleration merging feature. (docs)
So this should do the job:
// theFileYouDeclaredTheCustomConfigIn.ts
declare module 'axios' {
export interface AxiosRequestConfig {
handlerEnabled: boolean;
}
}
// in axios.d.ts
import 'axios';
declare module 'axios' {
export interface AxiosRequestConfig {
handlerEnabled?: boolean;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With