Type alias Awaitable<Type>

Awaitable<Type>: Promise<Type> | Type

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

type AwaitableString = Awaitable<string>;
const promisedValue: AwaitableString = Promise.resolve("🟢");
const plainValue: AwaitableString = "🟩";

Promise.all([promisedValue, plainValue]).then(console.log); // ["🟢", "🟩"]

See

Promise

Type Parameters

  • Type = unknown

    The type to await.