场景
在使用vue3+ts封装axios时,一直报错
Argument of type '(config: AxiosRequestConfig) => { headers: { synthesizejudge_token: string; }; url?: string | undefined; method?: string | undefined; baseURL?: string | undefined; transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[] | undefined; ... 31 more ...; formSerializer?: FormSerializerOptions | undefined; }' is not assignable to parameter of type '(value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
Type '{ headers: { synthesizejudge_token: string; }; url?: string | undefined; method?: string | undefined; baseURL?: string | undefined; transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[] | undefined; ... 31 more ...; formSerializer?: FormSerializerOptions | undefined; }' is not assignable to type 'InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
Type '{ headers: { synthesizejudge_token: string; }; url?: string | undefined; method?: string | undefined; baseURL?: string | undefined; transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[] | undefined; ... 31 more ...; formSerializer?: FormSerializerOptions | undefined; }' is not assignable to type 'InternalAxiosRequestConfig<any>'.
Types of property 'headers' are incompatible.
Type '{ synthesizejudge_token: string; }' is not assignable to type 'AxiosRequestHeaders'.
Type '{ synthesizejudge_token: string; }' is missing the following properties from type 'AxiosHeaders': set, get, has, delete, and 23 more.ts(2345)
原因
应该是新版本的bug 经过测试,axios@1.2.4之后的版本都不行,之前的版本可以