You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Indexing tuple intersection type beyond length produces unexpected typeΒ #42557
typeT=[number,boolean]&{x: string};declareconstt: T;consta=t[0];// numberconstb=t[1];// booleanconstc=t[2];// number | boolean !?
π Actual behavior
c is typed as number | boolean
π Expected behavior
c should be typed as undefined
I'm not sure if this is a bug, or intended behavior. But it was surprising. If the type is just a tuple, indexing beyond its length produced undefined. But if it is part of an intersection, the element type is changed to number | boolean, as if it is no longer a tuple, but an array. However, indexing 0 or 1 still produces the correct type for those element positions.
Activity
0xPoe commentedon Feb 2, 2021
Ryan Cavanaugh (@RyanCavanaugh) I would like to help fix the issue. Can you help with more information on fixing it?