Files
home/Projects/kompose/news/apps/backend/src/utils/pProps.ts
2025-10-08 10:35:48 +02:00

15 lines
401 B
TypeScript

export async function resolveProps<T extends Record<string, Promise<any>>>(
promises: T
): Promise<{ [K in keyof T]: Awaited<T[K]> }> {
const keys = Object.keys(promises)
const values = await Promise.all(Object.values(promises))
return keys.reduce(
(acc, key, index) => {
acc[key as keyof T] = values[index]
return acc
},
{} as { [K in keyof T]: Awaited<T[K]> }
)
}