Function guardNonEmptyArray

  • Enhances a Type Guard so it can be used to check all values of an array. It also checks if the array is non-empty.

    Returns

    A new Type Guard that takes an array

    Example

    import { isString, guardNonEmptyArray } from 'type-guard-helpers';
    const test = [] as unknown
    const isStringArray = guardNonEmptyArray((val): val is readonly [string, ...unknown[]] => isString(val[0]))
    if(isStringArray(test)){
    test; // test: readonly [string, ...unknown[]]
    }

    Type Parameters

    • Guard extends AnyTypeGuard<readonly [unknown, unknown], readonly [unknown, unknown]>

    Parameters

    • guard: Guard

      A Type Guard for valid array values

    Returns TypeGuardFn<unknown, GuardType<Guard>>

Generated using TypeDoc