diff --git a/source/tuple-to-union.d.ts b/source/tuple-to-union.d.ts index cf32b2d1d..1db246fb1 100644 --- a/source/tuple-to-union.d.ts +++ b/source/tuple-to-union.d.ts @@ -48,4 +48,4 @@ type NumberBool = typeof numberBool[number]; @category Array */ -export type TupleToUnion = ArrayType extends readonly [infer Head, ...(infer Rest)] ? Head | TupleToUnion : never; +export type TupleToUnion = ArrayType extends readonly unknown[] ? ArrayType[number] : never; diff --git a/test-d/tuple-to-union.ts b/test-d/tuple-to-union.ts index 1393e70f0..a05663337 100644 --- a/test-d/tuple-to-union.ts +++ b/test-d/tuple-to-union.ts @@ -24,3 +24,12 @@ expectType<'c'>(c); declare const notAnArray: TupleToUnion<[]>; expectType(notAnArray); + +declare const worksWithArrays: TupleToUnion>; +expectType(worksWithArrays); + +declare const resolvesToNeverForNonArrays: TupleToUnion; +expectType(resolvesToNeverForNonArrays); + +declare const infiniteRestArgs: TupleToUnion<[string, ...number[]]>; +expectType(infiniteRestArgs);