Interface CompiledSchema<T, S>

a compiled schema that allows various functions

interface CompiledSchema<T, S> {
    fuzz(): T;
    guard(inp): inp is T;
    schema(): S;
}

Type Parameters

  • T

    the type that this schema validates

  • S

    the type of the JTD schema that corresponds to this compiled schema

Methods

Methods

  • generate a random item that complies with this schema

    Returns T

    Example

    const schema = nullable(boolean());
    const val: boolean | null = schema.fuzz();
  • guard for if the input complies with the schema

    Parameters

    • inp: unknown

    Returns inp is T

    Example

    const schema = boolean();
    const val: unknown = // ...
    if (schema.guard(val)) {
    val satisfies boolean;
    }
  • produce the raw schema

    Returns S

    Example

    const schema = nullable(boolean);
    const raw: { type: "boolean", nullable: true } = schema.schema();