Closed
Description
TypeScript Version: 2.4.1
Code
export type TupleHasIndex<
Arr extends any[],
I extends number
> = ({[K in keyof Arr]: '1' } & Array<'0'>)[I];
// ^ #15768, TS2536 `X cannot be used to index Y` on generic
export type Inc = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
export type TupleToUnion<R extends any[], I extends number = 0, Acc = never> =
{ 1: TupleToUnion<R, Inc[I], Acc | R[I]>, 0: Acc }[TupleHasIndex<R, I>];
type TupleToUnionTest1 = TupleToUnion<['a', 'b']>;
// "a" | "b"
type TupleToUnionTest2 = TupleToUnion<string[]>;
// never
declare function toUnion<R extends string[]>(arr: R): TupleToUnion<R>;
const test1 = toUnion(['a', 'b']);
const arr: ['a', 'b'] = ['a', 'b'];
const test2 = toUnion(arr);
// ^ both: expecting 'a'|'b', got never
Expected behavior:
'a'|'b'
Actual behavior:
never
I'd reported a similar failure at #12290 (comment), though the thread had already been closed. These are possibly related to #16018, of generic types similarly failing when wrapped, even without functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels