tguard-js
    Preparing search index...

    Function isTuple

    • Determines whether the provided value is a tuple whose entries satisfy the given predicates in positional order.

      Type Parameters

      • T

        The tuple type inferred from the predicate list.

      Parameters

      • x: unknown

        The value to validate.

      • predicate: Predicate<T>

        A predicate used to validate the tuple elements.

      Returns x is readonly [T, T]

      true if the value satisfies the tuple structure, otherwise false.

      This function performs strict tuple validation by ensuring:

      • the value is an array
      • the array length exactly matches the predicate count
      • each element satisfies the predicate at the same index

      Unlike isArrayOf, tuple validation is positional and supports heterogeneous element types.

      • Tuple validation is strict and positional.
      • Extra or missing elements will cause validation to fail.
      • Predicates are evaluated in order.
      • At runtime, tuples are validated as standard JavaScript arrays.

      Validate a string-number tuple:

      isTuple(
      ['hello', 123],
      [isString, isNumber]
      ); // true

      Homogeneous tuple check:

      isTuple(
      ['foo', 'bar', '__not_foo_'],
      isString
      ); // true

      Invalid tuple length:

      isTuple(
      ['hello', 123, true],
      [isString, isNumber]
      ); // false

      Invalid tuple ordering:

      isTuple(
      [123, 'hello'],
      [isString, isNumber]
      ); // false

      Empty tuple:

      isTuple([], []); // true
      

      1.1

    • Type Parameters

      • T extends readonly unknown[]

        The tuple type inferred from the predicate list.

      Parameters

      • x: unknown

        The value to validate.

      • predicates: readonly [{ [K in string | number | symbol]: Predicate<T[K]> }]

        Predicates used to validate each tuple position.

      Returns x is T

      1.1