Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: functions dislike iteration? #17086

Closed
KiaraGrouwstra opened this issue Jul 11, 2017 · 1 comment
Closed

bug: functions dislike iteration? #17086

KiaraGrouwstra opened this issue Jul 11, 2017 · 1 comment

Comments

@KiaraGrouwstra
Copy link
Contributor

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.

@KiaraGrouwstra
Copy link
Contributor Author

I retested this again on master now, where test2 does in fact work. Closing as no longer relevant until I can find a new repro for master.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant