Generics to work with union/tuple in typescript
npm install union-tupleGenerics to work with union/tuple in typescript
bash
npm i -S union-tuple
`Interface
See what method or params you can use in index.d.tsUsage
$3
`typescript
import { IsTuple } from 'union-tuple'type Foo = IsTuple<[1, 2]>
const foo: Foo = true
`$3
`typescript
import { TupleToUnion } from 'union-tuple'type Foo = TupleToUnion<[1, 2]>
const foo: Foo = 1
`$3
`typescript
import { UnionPop } from 'union-tuple'type Foo = UnionPop<1 | 2>
const foo: Foo = 2
`$3
`typescript
import { TuplePrepend } from 'union-tuple'type Foo = TuplePrepend<[1, 2], 3>
const foo: Foo = [3, 1, 2]
`$3
`typescript
import { UnionToTuple } from 'union-tuple'type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
`$3
`typescript
import { UnionToTuple } from 'union-tuple'type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
`$3
`typescript
import { UnionToTupleWithMap } from 'union-tuple'type Foo = UnionToTupleWithMap<1 | 2 | 3, { 1: 'a', 2: 'c', 3: [1, 2] }>
const foo: Foo = ['a', 'c', [1, 2]]
`$3
`typescript
import { TupleMap } from 'union-tuple'type Foo = TupleMap<[2, 1, 3], { 1: 'a', 2: 'c', 3: [1, 2] }>
const foo: Foo = ['c', 'a', [1, 2]]
``