Skip to content

promiseAll

The promiseAll() function resolves all values from a tuple or an iterable, while preserving precise tuple typing for tuple inputs.

Interactive example

Syntax

typescript
function promiseAll<
	const GenericInput extends AnyTuple | Iterable<unknown>
>(
	input: GenericInput,
): GenericInput extends AnyTuple
	? Promise<{ -readonly [Prop in keyof GenericInput]: Awaited<GenericInput[Prop]>; }>
	: GenericInput extends Iterable<infer InferredValue>
		? Promise<Awaited<InferredValue>>[]
		: never;

Parameters

  • input: Tuple or iterable containing promises, direct values, or both.

Return value

  • If input is a tuple, returns a Promise of a resolved tuple with preserved structure.
  • If input is an iterable, returns the resolved Promise.all(...) result typed from iterable items.

See also

Released under the MIT license.