Hyperlinkv0.8.0-beta.28

Types

Types.TupleOftypeeffect/Types.ts:54
TupleOf<N, T>

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

  • If N is a literal number, produces a tuple of that exact length.
  • If N is the general number type (non-literal), degrades to Array<T>.
  • Negative numbers produce 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]
Source effect/Types.ts:541 lines
export type TupleOf<N extends number, T> = N extends N ? number extends N ? Array<T> : TupleOf_<T, N, []> : never
Referenced by 5 symbols