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
What if instead of trying shorter cryptic type that starts with 3 strings and ends with 2 numbers (no idea what API can be described this way, instead of an object), it was tuple with labeled elements so any user will know correct order of some strings and some numbers, not only type and count?
It's weird that the only use case listed for this is the same as the motivating example. Is there some actual real-world situation where tuples like this are being used that are so long as to be hard to use? I'd expect a motivating example to be like [string * 17, number * 7] or something, and a use case to be... like, some description of where such a monstrosity would actually be used.
Aaanyway, given that #26223 is closed as fixed you can do something like this yourself without too much trouble and without extra syntax:
interfaceTupleOfLength<T>{0: [];1: [T];2: [T,T];3: [T,T,T];// Keep going as far as you have to (????)}// S = [string, string, string]typeS=TupleOfLength<string>[3]
I would recommend this over clever conditional type tricks because it's more performant and there's no reason you can't list out the longest tuple you'd realistically have
Activity
IllusionMH commentedon Feb 14, 2022
What if instead of trying shorter cryptic type that starts with 3 strings and ends with 2 numbers (no idea what API can be described this way, instead of an object), it was tuple with labeled elements so any user will know correct order of some strings and some numbers, not only type and count?
jcalz commentedon Feb 14, 2022
It's weird that the only use case listed for this is the same as the motivating example. Is there some actual real-world situation where tuples like this are being used that are so long as to be hard to use? I'd expect a motivating example to be like
[string * 17, number * 7]or something, and a use case to be... like, some description of where such a monstrosity would actually be used.Aaanyway, given that #26223 is closed as fixed you can do something like this yourself without too much trouble and without extra syntax:
๐ โ
Playground link
fatcerberus commentedon Feb 14, 2022
This is terrifying
RyanCavanaugh commentedon Feb 14, 2022
This doesn't come up often enough that we would "spend" syntax/complexity on it.
RyanCavanaugh commentedon Sep 24, 2025
Alternative you can use btw
I would recommend this over clever conditional type tricks because it's more performant and there's no reason you can't list out the longest tuple you'd realistically have