isguard-ts
    Preparing search index...

    Function isTuple

    • Creates a TupleTypeGuard that validates that the array has the exact length and types match at each position.

      Best practice: pass the generic type argument into isTuple to avoid unexpected optional-field behavior.

      Type Parameters

      • T extends readonly unknown[]

        The tuple type to guard

      Parameters

      • template: TypeGuardTemplate<T>

        An array of type guards corresponding to each position in the tuple

      Returns TupleTypeGuard<T>

      A type guard for T

      type Row = [number, string?];
      const isRow = isTuple<Row>([isNumber, isString.optional()]);

      isRow([6, "Hello"]); // true
      isRow([6]); // true
      isRow(["Hello", "Bye"]); // false