A value that might be coming from a Promise.
Promise
Union type useful when you want to accept both Promise and non-Promise for a given type, both "awaitable".
type AwaitableString = Awaitable<string>;const promisedValue: AwaitableString = Promise.resolve("🟢");const plainValue: AwaitableString = "🟩";Promise.all([promisedValue, plainValue]).then(console.log); // ["🟢", "🟩"] Copy
type AwaitableString = Awaitable<string>;const promisedValue: AwaitableString = Promise.resolve("🟢");const plainValue: AwaitableString = "🟩";Promise.all([promisedValue, plainValue]).then(console.log); // ["🟢", "🟩"]
The type to await.
A value that might be coming from a
Promise
.Remarks
Union type useful when you want to accept both
Promise
and non-Promise
for a given type, both "awaitable".Example
See
Promise