Я думаю, что ответ на этот вопрос: нет, для этого нет встроенного типа.
В lib.es5.d.ts
и lib.es2015.promise.d.ts
они используют T | PromiseLike<T>
для различных мест, в которых ваш Awaitable<T>
будет иметь смысл, например:
/**
* Represents the completion of an asynchronous operation
*/
interface Promise<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}
Нет ничего похожего на ваши Awaitable
в lib.es5.d.ts
, где они определяют PromiseLike
и Promise
.
Я думаю, если бы они определили один, они использовали бы его в этих определениях.
Примечание: на основании этих определений, вероятно, имеет смысл использовать PromiseLike
вместо Promise
в вашем Awaitable
:
type Awaitable<T> = T | PromiseLike<T>;