import axios from 'axios';
import {Method} from 'axios'
let axiosIns = axios.create({
timeout: 15000,
});
const requestType = ['get', 'post', 'delete', 'put'];
interface requestObj {
[x: string]: any;
}
let request:requestObj={};
requestType.forEach((method:Method | string) => {
request[method] = function (uri:string, data:any) {
return new Promise(function (resolve, reject) {
axiosIns[method](uri, data)
.then((response:any) => {
resolve(response);
})
.catch((err:any) => {
reject(err);
});
});
};
});
在axiosIns[method]
会报错:
Element implicitly has an 'any' type because type 'AxiosInstance' has no index signature. Did you mean to call 'axiosIns.get'?ts(7052)
这里应该怎么写好呢?
如果method:string
换成method:Method
呢?
另外requestType改成枚举呢?