// 更新前
function afn<T>(fnArr: Array<() => Promise<T> > ) {
return fnArr;
}
type WithPromise<T> = () => Promise<T>;
interface Fn {
<T>(a: WithPromise<T>): Promise<[Promise<T>]>;
<T, K>(a: WithPromise<T>, b: WithPromise<K>): Promise<[Promise<T>, Promise<K>]>;
<T, K, P>(a: WithPromise<T>, b: WithPromise<K>, c: WithPromise<P>): Promise<[Promise<T>, Promise<K>, Promise<P>]>;
<T, K, P, Q>(a: WithPromise<T>, b: WithPromise<K>, c: WithPromise<P>, d: WithPromise<Q>): Promise<[Promise<T>, Promise<K>, Promise<P>, Promise<Q>]>;
(...args: Array<WithPromise<any>>): Promise<Array<Promise<any>>>;
}
const fn = ((...args: Array<WithPromise<any>>) => Promise.resolve(args.map((f) => f())) as unknown) as Fn;
fn(
function () {
return new Promise<string>((resolve) => resolve('222'));
},
() => Promise.resolve(1),
).then((arr) => {
arr[0].then((res) => res);
});
利用重载,可以自行加到 8- 10 个
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…