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

Type error emitted for valid type index lookups in variadic tuple types #40030

Closed
JoshuaKGoldberg opened this issue Aug 13, 2020 · 2 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Aug 13, 2020

TypeScript Version: 4.0.0-beta

Search Terms: cannot be used to index type tuple partial generic template variadic

Code

type WithOneMore<T extends unknown[]> = [...T, ''];

type LengthPlusOne<T extends unknown[]> = WithOneMore<T>['length'];

type TestNowFour = LengthPlusOne<['a', 'b', 'c']>;

Expected behavior:

There should be no type checker errors. TestNowFour is equal to the literal 4.

Actual behavior:

The following error is emitted for WithOneMore<T>['length']:

ts(2536): Type '"length"' cannot be used to index type '[...T, ""]'.

Interestingly, TestNowFour is computed to be equal to the literal 4 regardless of the error.

Playground Link: Playground Link

Related Issues: Nothing particularly close. #5453 tracked the variadic kinds proposal and #39094 implemented them. I am keenly looking at what's coming out of the recursive conditional types mentioned in #40006 though...

@tadhgmister
Copy link

as a work around [...T, ''] & {length: number} works as expected (playground)

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 3, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.1.0 milestone Sep 3, 2020
@ahejlsberg
Copy link
Member

No longer reproduces on 4.0.2 or master. I believe this was fixed before we shipped 4.0.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants