Last active
January 14, 2022 10:34
-
-
Save holgergp/9354af090f44ad59f33e0786e98d67c6 to your computer and use it in GitHub Desktop.
Awaited example from docs (TypeScript 4.5 article)
This file contains hidden or 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
// Error! | |
// | |
// [number | Promise<100>, number | Promise<200>] | |
// | |
// is not assignable to type | |
// | |
// [number, number] |
This file contains hidden or 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
declare function MaybePromise<T>(value: T): T | Promise<T> | PromiseLike<T>; |
This file contains hidden or 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
async function doSomething(): Promise<[number, number]> { | |
const result = await Promise.all([MaybePromise(100), MaybePromise(200)]); | |
return result; | |
} |
This file contains hidden or 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
declare function MaybePromise<T>(value: T): T | Promise<T> | PromiseLike<T>; | |
async function doSomething(): Promise<[number, number]> { | |
const result = await Promise.all([MaybePromise(100), MaybePromise(200)]); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment