根据文档axios-url-template,我正在尝试为我的react
typescript
应用程序使用url模板拦截器,
axios.interceptors.request.use(urlTemplateInterceptor({
urlAsTemplate: true,
}));
但它抛出以下错误。我错过了什么?
Argument of type '(config: AxiosRequestConfig<any>) => AxiosRequestConfig<any>' is not assignable to parameter of type '(value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
Type 'AxiosRequestConfig<any>' is not assignable to type 'InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
Type 'AxiosRequestConfig<any>' is not assignable to type 'InternalAxiosRequestConfig<any>'.
Types of property 'headers' are incompatible.
Type 'AxiosHeaders | (Partial<RawAxiosHeaders & { Accept: AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "User-Agent": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; Authorization: AxiosHeaderValue; } & { ...; }> & Partial<...>) | undefined' is not assignable to type 'AxiosRequestHeaders'.
Type 'undefined' is not assignable to type 'AxiosRequestHeaders'.
Type 'undefined' is not assignable to type 'Partial<RawAxiosHeaders & { Accept: AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "User-Agent": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; Authorization: AxiosHeaderValue; } & { ...; }>'.ts(2345)
(alias) urlTemplateInterceptor(options?: UrlTemplateInterceptorOptions | undefined): (config: AxiosRequestConfig<any>) => AxiosRequestConfig<any>
import urlTemplateInterceptor
1条答案
按热度按时间3duebb1j1#
根据需要实现了自定义拦截器,并且工作正常。