• P.intersection(...patterns) returns a pattern which matches only if every patterns provided in parameter match the input.

    Read the documentation for P.intersection on GitHub

    Type Parameters

    Parameters

    Returns Chainable<AndP<input, patterns>>

    Example

    match(value)
    .with(
    {
    user: P.intersection(
    { firstname: P.string },
    { lastname: P.string },
    { age: P.when(age => age > 21) }
    )
    },
    ({ user }) => 'will match { firstname: string, lastname: string, age: number } if age > 21'
    )