ts-array-as-tuple
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i ts-array-as-tuple

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.47 kB

Total Files

7

Last publish

Collaborators

  • springworks