Skip to content

makeRecordGuard

Jason Godesky edited this page Aug 19, 2026 · 1 revision

makeRecordGuard is a method that returns a type guard that asserts that the candidate passed in is a record of the form Record<string, T>.

Parameters

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

A type guard that the record guard will run against each value in a given object.

Returns

A type guard that asserts that the candidate passed to it is a record of the form Record<string, T>

Examples

import { isNumber, makeRecordGuard } from '@revolutionarygamesco/common'

const isNumberRecord = makeRecordGuard<number>(isNumber)
isNumberRecord({ a: 1, b: 2 }) // true
isNumberRecord({}) // true
isNumberRecord({ a: 1, b: '2' }) // false; a is a number but b is not
isNumberRecord(1) // false
isNumberRecord([1, 2]) // false

Clone this wiki locally