const METHODS_TYPES = ['get', 'post', 'put', 'patch', 'delete'] as const;
type METHODS_TUPLE = typeof METHODS_TYPES;
type METHODS = METHODS_TUPLE[number];
function methodRequest(url: string, method: METHODS): any {
axios[method](url);
}
我有类似上面的函数,可以根据方法输入动态调用axios请求。看来合乎逻辑,但打字稿抱怨道:
“联合类型的每个成员'(>(url: 字符串,配置?:AxiosRequestConfig |未定义)=>承诺)| (>((URL:字符串,数据?:任何,配置?:AxiosRequestConfig |未定义)=> Promise <...>)| (>(url:字符串,数据?:任何,配置?: AxiosRequestConfig | undef ...”有签名,但没有一个 签名彼此兼容”
你们知道这个问题吗?