Skip to content

callThen

The callThen() function applies a callback directly to a value, or waits for a Promise before running the same callback.

Interactive example

Syntax

typescript
function callThen<
	GenericInput extends unknown,
	GenericOutput extends unknown,
>(
	input: GenericInput,
	TheFunction: (
		input: Awaited<GenericInput>
	) => GenericOutput,
): GenericInput extends Promise<unknown>
	? Promise<Awaited<GenericOutput>>
	: GenericOutput;

Parameters

  • input : Direct value or Promise to transform.
  • TheFunction : Callback executed with the resolved value of input.

Return value

  • If input is a direct value, returns the callback output.
  • If input is a Promise, returns a Promise resolved with the callback output.

See also

Released under the MIT license.