该报错可能是由于 axios 类型定义有误导致的,需要对 axios 的类型定义进行修正。具体做法如下:

  1. 找到 axios 的类型定义文件,一般为'index.d.ts' 或 'axios.d.ts'。
  2. 在该文件中找到'axios' 函数的定义,一般为:
declare function axios<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;

declare namespace axios {
  // ...
}
  1. 修改该函数的定义,添加一个泛型参数'R',用于指定响应数据的类型:
declare function axios<T = any, R = IResponseData<T>>(config: AxiosRequestConfig): AxiosPromise<R>;

declare namespace axios {
  // ...
}
  1. 在调用'axios.get'时,指定泛型参数'T',用于指定响应数据的类型:
export const getKnowledgePage = <T>(params: KnowledgeParams) =>
  axios.get<IResponseData<T>>(USER_API.gethome, { params });

这样就可以避免报错了。


原文地址: https://www.cveoy.top/t/topic/oXbX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录