tguard-js
    Preparing search index...

    Function isArrayOf

    • Determines whether the provided value is an array whose elements satisfy the given predicate.

      Type Parameters

      • T

        The expected element type.

      Parameters

      • x: unknown

        The value to be checked.

      • predicate: Predicate<T>

        A type guard used to validate each element.

      Returns x is T[]

      true if the value is an array and all elements satisfy the predicate, otherwise false.

      This function first checks if the value is an array, then validates each element using the provided predicate.

      The predicate must be a type guard (v is T) to ensure correct type narrowing.

      An empty array returns true, since no elements violate the predicate.

      Value Predicate Result
      [1, 2, 3] isNumber true
      [1, 'a'] isNumber false
      [] isNumber true
      'text' isString true
      {} isString false

      This function also supports union types checking:

      isArrayOf<string | number>(x, (v) => isString(v) || isNumber(v));
      

      1.0