Package: effect
Module: Tuple
Checks whether an array has exactly N elements, narrowing the type to a
fixed-length tuple.
When to use
Use to guard that an array has exactly the tuple length expected at runtime.
Details
This is a re-export of Predicate.isTupleOf. It narrows the type to
TupleOf<N, T> in the truthy branch.
Gotchas
This only checks .length; it does not validate element types.
Example (Checking exact length)
import { Tuple } from "effect"
const arr: Array<number> = [1, 2, 3]
if (Tuple.isTupleOf(arr, 3)) {
console.log(arr)
// ^? [number, number, number]
}
See
isTupleOfAtLeast – check for a minimum lengthSignature
declare const isTupleOf: { <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>; <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>; }
Since v3.3.0