Function guardArray

  • Given a Type Guard, returns a Type Guard that checks if the given value is an array and matches the given Type Guard.

    Example

    import { guardArray } from 'type-guard-helpers';

    const isStringArray = guardArray(
    (value): value is readonly string[] =>
    value.findIndex((item) => typeof item !== 'string') === -1
    );

    const test = {} as unknown;
    if (isStringArray(test)) {
    test; // test: readonly string[]
    }

    Type Parameters

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

    Parameters

    • guard: Guard

    Returns TypeGuardFn<unknown, GuardType<Guard>>

Generated using TypeDoc