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
But is the request here just a simple utility type? As far as I know, there's no way you can write Tuple<L, T> in your own code right now. T[] & { length: L } doesn't stop you from indexing outside of the expected range.
As far as I know, there's no way you can write Tuple<L, T> in your own code right now.
typeTupleMap<T>={0: [],1: [T],2: [T,T],3: [T,T,T]// go as far as you need to}typeTupleN<NextendskeyofTupleMap<unknown>,T>=TupleMap<T>[N];typeRGB=TupleN<3,number>;
I really recommend the lookup type method over tail-recursion wizardry in any case where you have a reasonable finite bound; it's generally more performant and easier to read.
Activity
olivermrose commentedon Jun 22, 2023
#51841 (comment)
nmain commentedon Jun 22, 2023
But is the request here just a simple utility type? As far as I know, there's no way you can write
Tuple<L, T>in your own code right now.T[] & { length: L }doesn't stop you from indexing outside of the expected range.fatcerberus commentedon Jun 22, 2023
If the request is more than just the utility type then this is an essentially a duplicate of #47874 with different syntax.
fatcerberus commentedon Jun 22, 2023
As for the utility type itself, apparently you can already implement it today: #47874 (comment)
RyanCavanaugh commentedon Jun 22, 2023
I really recommend the lookup type method over tail-recursion wizardry in any case where you have a reasonable finite bound; it's generally more performant and easier to read.