/**
* @format
*
* These are where we put all the type aliases, interfaces, and enumerations that are shared
* between multiple things, or may be useful to use without us.
*
* @packageDocumentation
*/
///
/**
* Provides the type of elements within an `Iterable`, which may be wrapped in one or more promises.
* The element type is also unwrapped any promises.
*/
export type Item = Unpromise extends Array
? U
: Unpromise extends Iterable
? U
: never;
/**
* Provides the type of the resolution value after unwrapping all the `PromiseLike` and [[`Promisable`]] interfaces (if any).
*/
export type Unpromise = T extends PromiseLike
? Unpromise
: T extends Promisable
? U extends T
? T
: Unpromise
: T;
/**
* Something which can be resolved: that is, either a value or a promise of a value.
*/
export type Promisable = T | PromiseLike;
/**
* Guarantees that there is only one `Promise` wrapper.
*/
export type SimplifiedPromise = Promise>;
/**
* Guarantees that there is only one `PromiseLike` wrapper.
*/
export type SimplifiedPromiseLike = PromiseLike>;
/**
* Guarantees that there is at most one `PromiseLike` wrapper.
*/
export type SimplifiedPromisable = Promisable>;
/**
* An `Iterable` or a promise of an `Iterable`. Its elements are any mix of type `T` and/or `PromiseLike`.
* Used as a type for arguments.
*/
export type PromisableIterable = Promisable>;
/**
* Represents an `Iterable` that is not a promise but an actual value that is an `Iterable`,
* although it may produce either values or promises of values or both.
*/
export type IterableOfPromisables = Iterable>;
/**
* Represents a `PromiseSettledResult` value for a fulfilled promise.
*/
export class Fulfillment implements PromiseFulfilledResult {
constructor(public readonly value: T) {}
get status(): "fulfilled" {
return "fulfilled";
}
}
/**
* Represents a `PromiseSettledResult` value for a rejected promise.
*/
export class Rejection implements PromiseRejectedResult {
constructor(public readonly reason: unknown) {}
get status(): "rejected" {
return "rejected";
}
}
/**
* Equivalent to a `PromiseSettledResult`, but specific to our classes.
*/
export type Settlement = PromiseSettledResult &
(Fulfillment | Rejection);