union-tuple
v1.1.2
Published
Generics to work with union/tuple in typescript
Downloads
208
Maintainers
Readme
union-tuple
Generics to work with union/tuple in typescript
repository
https://github.com/livelybone/union-tuple.git
Demo
https://github.com/livelybone/union-tuple#readme
Installation
npm i -S union-tuple
Interface
See what method or params you can use in index.d.ts
Usage
IsTuple
import { IsTuple } from 'union-tuple'
type Foo = IsTuple<[1, 2]>
const foo: Foo = true
TupleToUnion
import { TupleToUnion } from 'union-tuple'
type Foo = TupleToUnion<[1, 2]>
const foo: Foo = 1
UnionPop
import { UnionPop } from 'union-tuple'
type Foo = UnionPop<1 | 2>
const foo: Foo = 2
TuplePrepend
import { TuplePrepend } from 'union-tuple'
type Foo = TuplePrepend<[1, 2], 3>
const foo: Foo = [3, 1, 2]
UnionToTuple
import { UnionToTuple } from 'union-tuple'
type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
UnionToTuple
import { UnionToTuple } from 'union-tuple'
type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
UnionToTupleWithMap
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]]
TupleMap
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]]