Package: effect
Module: Types
Constructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
N is a literal number, produces a tuple of that exact length.N is the general number type (non-literal), degrades to Array<T>.never.Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
// @ts-expect-error - too few elements
const tooFew: Types.TupleOf<3, number> = [1, 2]
// @ts-expect-error - too many elements
const tooMany: Types.TupleOf<3, number> = [1, 2, 3, 4]
See
TupleOfAtLeastSignature
type TupleOf<N, T> = N extends N ? number extends N ? Array<T> : TupleOf_<T, N, []> : never
Since v3.3.0