From 2e3ae207c2b367cdadcfbf4178d372917bdbffc3 Mon Sep 17 00:00:00 2001 From: Josh Rosenstein <32781407+JoshRosenstein@users.noreply.github.com> Date: Sun, 14 Apr 2019 21:23:43 -0400 Subject: [PATCH] feat: improve IntersectTuple --- src/types/tuples.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/types/tuples.ts b/src/types/tuples.ts index 7783a66..f25e80d 100644 --- a/src/types/tuples.ts +++ b/src/types/tuples.ts @@ -1,3 +1,5 @@ +import {UnionToIntersection} from './utils'; + export interface Vector { readonly [x: number]: T; readonly length: number; } export type Length> = T['length']; @@ -12,15 +14,4 @@ export type UnionizeTuple> = T[number]; * @param T a tuple of items up to 10 * @returns an intersection of all items in the tuple */ -export type IntersectTuple> = - Length extends 1 ? T[0] : - Length extends 2 ? T[0] & T[1] : - Length extends 3 ? T[0] & T[1] & T[2] : - Length extends 4 ? T[0] & T[1] & T[2] & T[3] : - Length extends 5 ? T[0] & T[1] & T[2] & T[3] & T[4] : - Length extends 6 ? T[0] & T[1] & T[2] & T[3] & T[4] & T[5] : - Length extends 7 ? T[0] & T[1] & T[2] & T[3] & T[4] & T[5] & T[6] : - Length extends 8 ? T[0] & T[1] & T[2] & T[3] & T[4] & T[5] & T[6] & T[7] : - Length extends 9 ? T[0] & T[1] & T[2] & T[3] & T[4] & T[5] & T[6] & T[7] & T[8] : - Length extends 10 ? T[0] & T[1] & T[2] & T[3] & T[4] & T[5] & T[6] & T[7] & T[8] & T[9] : - any; +export type IntersectTuple>= UnionToIntersection;