Skip to content

Commit

Permalink
fix all type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 4, 2024
1 parent 0c37457 commit 0eec13f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/async/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export async function all<T extends Record<string, Promise<any>>>(
promises: T,
): Promise<{ [K in keyof T]: Awaited<T[K]> }>

export async function all<
T extends Record<string, Promise<any>> | Promise<any>[],
>(promises: T) {
export async function all(
promises: Record<string, Promise<any>> | Promise<any>[],
): Promise<any> {
const entries = isArray(promises)
? promises.map(p => [null, p] as [null, Promise<any>])
? promises.map(p => [null, p] as const)
: Object.entries(promises)

const results = await Promise.all(
Expand All @@ -63,16 +63,14 @@ export async function all<
}

if (isArray(promises)) {
return results.map(r => r.result) as T extends Promise<any>[]
? PromiseValues<T>
: unknown
return results.map(r => r.result)
}

return results.reduce(
(acc, item) => {
acc[item.key as keyof T] = item.result
acc[item.key!] = item.result
return acc
},
{} as { [K in keyof T]: Awaited<T[K]> },
{} as Record<string, any>,
)
}

0 comments on commit 0eec13f

Please sign in to comment.