• isMatching takes pattern and returns a type guard function, cheching if a value matches this pattern.

    Read documentation for isMatching on GitHub

    Type Parameters

    • const p extends UnknownPattern

    Parameters

    • pattern: p

    Returns ((value) => value is infer<p>)

      • (value): value is infer<p>
      • Parameters

        • value: unknown

        Returns value is infer<p>

    Example

    const hasName = isMatching({ name: P.string })

    declare let input: unknown

    if (hasName(input)) {
    // `input` inferred as { name: string }
    return input.name
    }
  • isMatching takes pattern and a value and checks if the value matches this pattern.

    Read documentation for isMatching on GitHub

    Type Parameters

    • const p extends UnknownPattern

    Parameters

    • pattern: p
    • value: unknown

    Returns value is InvertPattern<p, unknown>

    Example

    declare let input: unknown

    if (isMatching({ name: P.string }, input)) {
    // `input` inferred as { name: string }
    return input.name
    }