Skip to content

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

Description

@JoshuaKGoldberg

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...

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions