UNPKG

@quinck/collections

Version:

Allows extra operations on JavaScript collections: Array, Map and Set.

40 lines (39 loc) 1.67 kB
export {}; import './collect'; export type PromiseError = Error | unknown; declare global { interface Array<T> { /** * Applicable to arrays of promises. * Awaits all the promises elements of the array to be fulfilled. * @returns the elements of the array awaited * @throws {@link Error} if any promise fails */ awaitAll(): Promise<Array<Awaited<T>>>; /** * Applicable to arrays of promises. * Awaits all the promises elements of the array to be settled. * If a promise fulfills the item will be replaced with its awaited version, * if a promise rejects the item will be replaced with the error reported. * @returns an array of PromiseSettledResult with both fulfilled and rejected promises elements * @throws {@link Error} if any promise fails */ tryToAwaitAll(): Promise<Array<PromiseSettledResult<Awaited<T>>>>; /** * Applicable to arrays of promises. * Awaits all the promises elements of the array to be settled, * discarding elements that does not fulfills. * @returns the elements of the array awaited * @throws {@link Error} if any promise fails */ awaitAllFulfilled(): Promise<Array<Awaited<T>>>; /** * Applicable to arrays of promises. * Awaits all the promises elements of the array to be settled, * taking only the rejected. * @returns the elements of the array awaited * @throws {@link Error} if any promise fails */ awaitAllRejected(): Promise<Array<PromiseError>>; } }