Last active
August 25, 2022 12:57
-
-
Save Luisgustavom1/9bf3b6861c04819ea6e04625ceac8b2c to your computer and use it in GitHub Desktop.
Type-challenges - 20 Medium Promise.all (https://github.com/type-challenges/type-challenges/blob/main/questions/00020-medium-promise-all/README.md)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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