Skip to main content

Function: isArray()

function isArray<T>(
value: unknown,
itemValidator?: (item: unknown) => item is T
): value is T[];

Defined in: shared/utils/typeGuards.ts:115

Determines whether a value is an array and optionally validates each element.

Type Parametersโ€‹

Tโ€‹

T = unknown

Element type enforced by the optional validator.

Parametersโ€‹

valueโ€‹

unknown

Value to evaluate.

itemValidator?โ€‹

(item: unknown) => item is T

Optional guard applied to each array element.

Returnsโ€‹

value is T[]

true when the value is an array and all elements pass the guard.

Exampleโ€‹

if (isArray(arr, isString)) {
// arr is string[]
}