GuardsArray Guards
Check Array of Type
Validates that element(s) in an array match a specific type guard.
isArrayOfType
Validates that all elements in an array match a specific type guard. Useful for checking homogeneous collections from untyped sources.
Signature
function isArrayOfType<T>(
value: unknown,
typeCheck: (item: unknown) => item is T
): value is T[]Examples
playground.ts
Use Cases
- Validating API response arrays
- Processing CSV/JSON data
- Sanitizing user-provided arrays
- Runtime validation of typed collections
isFirstElementOfType
Validates that the first element of an array matches a specific type guard. Useful for checking homogeneous collections from untyped sources.
Import
import { isFirstElementOfType } from 'toolbox-x/guards';Signature
function isFirstElementOfType<T>(
value: unknown,
typeCheck: (item: unknown) => item is T
): value is T[]Warning
This guard only checks the first element of the array. It does not check the rest of the elements. Use isArrayOfType for a more comprehensive check.
Examples
playground.ts
Use Cases
- Validating API response arrays
- Processing CSV/JSON data
- Sanitizing user-provided arrays
Last updated: Sat, Jul 18, 2026 09:05:02PM (UTC)
