UNPKG

385 BPlain TextView Raw
1export type PromiseProps<T> = { [K in keyof T]?: Promise<T[K] | undefined> };
2export async function promiseProps<T extends Record<string, unknown>>(obj: PromiseProps<T>): Promise<T> {
3 const promKeys = Object.keys(obj) as (keyof T)[];
4 return (await Promise.all(Object.values(obj)))
5 .reduce((acc: T, cur, idx) => {
6 acc[promKeys[idx]] = cur;
7 return acc;
8 }, {});
9}