这是一个需要指定返回类型的函数
export const getDashboard = (date: TRange): any => {
return Promise.all([
StatisticService.getCustomerChart(date),
StatisticService.getOrderChart(date),
StatisticService.getPartnerChart(date),
StatisticService.getWorkerChart(date),
])
};
这是从中获取方法的类
export class StatisticService {
static getCustomerChart(date: TRange): TResponseMany<IStatistic> {
const queryParams = getQueryParams(date);
return customFetch(URLS.STATISTICS.CUSTOMER, queryParams);
}
static getOrderChart(date: TRange): TResponseMany<IStatistic> {
const queryParams = getQueryParams(date);
return customFetch(URLS.STATISTICS.ORDER, queryParams);
}
static getPartnerChart(date: TRange): TResponseMany<IStatistic> {
const queryParams = getQueryParams(date);
return customFetch(URLS.STATISTICS.PARTNER, queryParams);
}
static getWorkerChart(date: TRange): TResponseMany<IStatistic> {
const queryParams = getQueryParams(date);
return customFetch(URLS.STATISTICS.WORKER, queryParams);
}
}
和更多接口
interface IResponseMany<T> extends IResponseDetails {
body: T[];
}
export type TResponseMany<T> = Promise<IResponseMany<T>>;
export interface IStatistic {
creationDate: string;
count: number;
}
返回的类型
Promise.all对应一个数组,其元素是传递的值Promise。在这种情况下,所有函数都返回
Prommise<IResponseMany<T>>,所以返回类型将是Promise<IResponseMany<T>[]>