Function guard

  • Validate and cast an input

    Type Parameters

    • T

      The validated type

    Parameters

    • validator: Validator<T>

      The validator to convert

    • input: unknown

    Returns input is T

    Example

    if (guard(isNumber, input)) {
    // input is treated as a number in this block
    }