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

  1. 找到axios的类型定义文件,一般为index.d.tsaxios.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 });

这样就可以避免报错了

export const getKnowledgePage = Tparams KnowledgeParams = axiosgetany IResponseDataTUSER_APIgethome params报错解决

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

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