type Await = T extends Promise ? U : T; type AwaitAll = { [P in keyof T]: Await; }; export async function awaitAll(obj: T): Promise> { const target = {} as any; const keys = Object.keys(obj); const rawValues = Object.values(obj); const retValues = ((values: any[]): any[] => values.map(value => { if (!value || !value.constructor || value.constructor.name !== 'Object') return value; return awaitAll(value); }) )(rawValues); const values = await Promise.all(retValues); for (let i = 0; i < values.length; i++) { target[keys[i]] = values[i]; } return target; }