Skip to main content
Module

x/scaffold/src/deps/types.ts>ReadonlyTuple

scaffold your next project with style and 💗
Latest
type alias ReadonlyTuple
import { type ReadonlyTuple } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

Create a type that represents a read-only tuple of the given type and length.

Use-cases:

  • Declaring fixed-length tuples with a large number of items.
  • Creating a range union (for example, 0 | 1 | 2 | 3 | 4 from the keys of such a type) without having to resort to recursive types.
  • Creating a tuple of coordinates with a static length, for example, length of 3 for a 3D vector.

Examples

Example 1

import {ReadonlyTuple} from 'type-fest';

type FencingTeam = ReadonlyTuple<string, 3>;

const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];

const homeFencingTeam: FencingTeam = ['George', 'John'];
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'

guestFencingTeam.push('Sam');
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'

Type Parameters

Element
Length extends number
definition: number extends Length ? readonly Element[] : BuildTupleHelper<Element, Length, []>