Function is

  • The is function allows you to verify that a given input matches a given schema.

    Example

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

    const data: unknown = 3;

    if (is(number)(data)) {
    console.log(data * 3);
    }

    Type Parameters

    • S

    Parameters

    • schema: Schema<S>

      The schema to test.

    Returns ((data) => data is S)

    A function returning a boolean that indicates whether the input matches the schema. The function is a type predicate, meaning that after testing the return value, TypeScript will now that the unknown input is of the tested type.

      • (data): data is S
      • Parameters

        • data: unknown

        Returns data is S