我正面临有关index.d.ts文件中公开的lambda函数的打字稿问题。我想做的是装饰AxiosInstance,以便在需要时取消待处理的请求。
这是axios库中的index.d.ts文件:
export interface AxiosInstance {
(config: AxiosRequestConfig): AxiosPromise; // How to override this lambda ?
(url: string, config?: AxiosRequestConfig): AxiosPromise; // How to override this lambda ?
// Omit the rest because ther is no problem with it
}
这是我对AxiosInstance的实现
export default class CancelableAxiosInstance implements AxiosInstance {
private axiosInstance: AxiosInstance;
constructor(axiosInstance: AxiosInstance){
this.axiosInstance = axiosInstance;
}
// Another function that I want to expose on CancelableAxiosInstance
cancelRequests() {
// Omit implementation
}
// How do I override (config: AxiosRequestConfig): AxiosPromise; declared in index.d.ts file ?
}
这是IDE中显示的我的打字稿编译器错误:
TS2420: 类'CancelableAxiosInstance'错误地实现了接口'AxiosInstance'。 类型'CancelableAxiosInstance'提供的签名不匹配(配置:AxiosRequestConfig):AxiosPromise。
有人可以帮助我吗?
非常感谢