effect-io-ai

Package: effect
Module: Types

Types.TupleOf

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

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

Signature

type TupleOf<N, T> = N extends N ? number extends N ? Array<T> : TupleOf_<T, N, []> : never

Source

Since v3.3.0