Skip to content

makeTupleGuard

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

makeTupleGuard is a method that returns a type guard that asserts that the candidate passed in is a tuple of a precise length with precise types.

Parameters

...guards: Guards<T>

The type guards that should be applied to each member of the tuple in order.

Returns

A type guard that asserts that the candidate passed to it is a tuple that tests each element against each guard provided, in the order provided.

Examples

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

const isNumStr = makeTupleGuard(isNumber, isString)

isNumStr([42, 'hello!']) // true
isNumStr(['hello!', 42]) // false
isNumStr([42, 'hello!', true]) // false
isNumStr([]) // false
isNumStr([42]) // false
isNumStr(['hello!]) // false
isNumStr(42) // false
isNumStr('hello!) // false
isNumStr({ num: 42, str: 'hello!' }) // false

Clone this wiki locally