Skip to content

makeArrayGuard

Jason Godesky edited this page Jul 11, 2026 · 1 revision

makeArrayGuard is a method that returns a type guard that asserts that the candidate passed in is an array and that each element of that array matches the type guard provided.

Parameters

singular: (candidate: unknown) => candidate is T

A type guard that the array guard will run against each element in a given array.

Returns

A type guard that asserts that the candidate passed to it is an array and that each element of that array passes the singular type guard passed to it.

Examples

import { isNumber, isString, makeArrayGuard } from '@revolutionarygamesco/common'

// This is literally how we define our isNumberArray method.
const isNumberArray: (
  candidate: unknown
) => candidate is number[] = makeArrayGuard<number>(isNumber)

// This is literally how we define our isStringArray method.
const isStringArray: (
  candidate: unknown
) => candidate is number[] = makeArrayGuard<string>(isString)

See also

Clone this wiki locally