-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 4.0.0-dev.20200625
Search Terms:
negative tuple indexer
Code
type t1 = [string, number][0]; // string
type t2 = [string, number][1]; // number
type t3 = [string, number][-1]; // (string | number) ???
type u<t extends any[], u extends number> = t[u];
type u1 = u<[string, number], 0>; // string
type u2 = u<[string, number], 1>; // number
type u3 = u<[string, number], 2>; // undefined
type u4 = u<[string, number], 1.5>; // undefined
type u5 = u<[string, number], -0.5>; // (string | number) ???Expected behavior:
that type t3 = [string, number][-1]; emits a compile-time error "Tuple type '[string, number]' of length '2' has no element at index '-1'." and u5 is undefined.
Actual behavior:
t3 and u5 is a union of the types contained in the tuple.
Playground Link: playground link
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript