Type alias Predicate<Input, Predicated>

Predicate<Input, Predicated>: Unary<Input, boolean> | ((input) => input is Predicated)

Unary function that returns a boolean.

Remarks

This type is useful for cases where a function needs to check if a certain condition holds for an input value. For example, the type of a function that checks if a number is even could be typed as Predicate<number>, a filtering function could look like Predicate<string | number, string>, and so on.

Example

const isEven: Predicate<number> = number => number % 2 === 0;

See

Param

The input value to check.

Returns

true if the predicate holds for the input value, and false otherwise.

Type Parameters

  • Input

    The type of the input value.

  • Predicated extends Input = Input

    The subset of Input for which the predicate holds.