Function set

  • The set schema validates that the input is a set of elements that match the schema. It fails for anything that is not a set, or for any element of the set that does not match the schema.

    Example

    import { set, number } from "typerun/schema";
    import { is } from "typerun";

    const isSet = is(set(number))(new Set([1, 2, 3]));
    console.log(isSet); // true

    const isNotSet = is(set(number))([1, 2, 3]);
    console.log(isNotSet); // false

    const isNotCorrectSet = is(set(number))(new Set([1, 2, "3"]));
    console.log(isNotCorrectSet); // false

    Type Parameters

    • S

    Parameters

    • schema: Schema<S>

      The schema to validate the elements of the set.

    Returns Schema<Set<S>>