Skip to content

Instantly share code, notes, and snippets.

@Luisgustavom1
Last active August 25, 2022 12:57
Show Gist options
  • Save Luisgustavom1/9bf3b6861c04819ea6e04625ceac8b2c to your computer and use it in GitHub Desktop.
Save Luisgustavom1/9bf3b6861c04819ea6e04625ceac8b2c to your computer and use it in GitHub Desktop.
type PromiseAllType<P> =
P extends []
? []
: P extends [Promise<infer T> | infer T, ...infer F]
? [T, ...PromiseAllType<F>]
: never
declare function PromiseAll<P extends any[]>(args: readonly [...P]): Promise<PromiseAllType<P>>
const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise<string>((resolve, reject) => {
setTimeout(resolve, 100, 'foo');
});
// expected to be `Promise<[number, 42, string]>`
const p = PromiseAll([promise1, promise2, promise3] as const)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment