ts-array-as-tuple

v1.0.1
Function that asserts the length of an array and casts it to a tuple.

ts-array-as-tuple

Function that asserts the length of an array and casts it to a tuple.

Example

import { asTuple } from 'ts-array-as-tuple';

const array: string[] = 'hello world'.split(' ');

const tuple: [string, string] = asTuple(array, 2);

asTuple(array, 1);
// Error: Unexpected array length, expected 1 but got 2.

asTuple(array, 3);
// Error: Unexpected array length, expected 3 but got 2.
npm i ts-array-as-tuple

Metadata

  • MIT
  • Whatever
  • David Brockman Smoliansky
  • released 7/23/2018

Downloads

Maintainers