• P.when((value) => boolean) returns a pattern which matches if the predicate returns true for the current input.

    Read the documentation for P.when on GitHub

    Type Parameters

    • input
    • predicate extends ((value) => unknown)

    Parameters

    Returns GuardP<input, predicate extends ((value) => value is infer narrowed)
        ? narrowed
        : never>

    Example

    match<{ age: number }>(value)
    .with({ age: P.when(age => age > 21) }, (x) => 'will match if value.age > 21'
    )
  • Type Parameters

    • input
    • narrowed
    • excluded

    Parameters

    Returns GuardExcludeP<input, narrowed, excluded>