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
Incorrect typing when flip-flopping an array of tuples #10094
constx: [string,number][]=[['one',1],['two',2],['three',3]];// Type of y should be [number,string][]// Instead, it is (number|string)[][]consty=x.map(([a,b])=>[b,a]);
Expected behavior:
This may be an expected feature of the language, and if so, please disregard.
Activity
weswigham commentedon Aug 2, 2016
As a workaround, you can cast your result:
Or, a personal favorite, write your own 'tuple constructor', which forces a tuple type to be inferred:
In any case, I think this is a duplicate of #6574, and discussion should probably continue there.
dsifford commentedon Aug 2, 2016
Whoops! Didn't see the other discussion. Sorry about that.
And yep, I've been using casting. Totally not a giant issue for me, but just wanted to throw it out there.
Love the tuple constructor! Clever!
Thanks again 👍