Generics to work with union/tuple in typescript
https://github.com/livelybone/union-tuple.git
https://github.com/livelybone/union-tuple#readme
npm i -S union-tuple
去 index.d.ts 查看可用方法和参数
import { IsTuple } from 'union-tuple'
type Foo = IsTuple<[1, 2]>
const foo: Foo = true
import { UnionPop } from 'union-tuple'
type Foo = UnionPop<1 | 2>
const foo: Foo = 2
import { TuplePrepend } from 'union-tuple'
type Foo = TuplePrepend<[1, 2], 3>
const foo: Foo = [3, 1, 2]
import { UnionToTuple } from 'union-tuple'
type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
import { UnionToTuple } from 'union-tuple'
type Foo = UnionToTuple<1 | 2 | 3>
const foo: Foo = [1, 2, 3]
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]]
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]]