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
Spreading tuple into generic/type arguments #39648
Allow spreading of a tuple type into type arguments.
The idea is that a tuple of n elements gets spread into generic arguments with r arguments. If n is larger than r, only the first r items are used. If n is smaller than r it is possible to add elements after the spread argument. E.g.
This would be particularly useful for interacting with libraries that use generics that take multiple arguments rather than an object type. A situation I find myself in.
Reacted by Sean Blonien, Zenon 'SI, Peter Severin Rasmussen, Spencer Marx, Yokoiwa Hiroki, Parker M, Wes Bos, Nick Schmitt, CEUK, Misha Berezin and 1 more
add defaults to all but the first two. what the defaults are will depend on the type. this can be unknown, never, or a custom unique symbol used as a sentinel value.
and that's it
(what this proposal would be adding is the ability to bundle up the array of parameters and pass the array around)
I believe this would also be useful to do some meta-programming, where in my case, I am taking a class constructor and extending it within a function. This would allow me to extract all the type parameters from the input constructor, and apply them to the output constructor.
Activity
somebody1234 commentedon Aug 9, 2021
one workaround could potentially be using an object (?) type instead?
byronbroughten commentedon Jan 20, 2022
This would be particularly useful for interacting with libraries that use generics that take multiple arguments rather than an object type. A situation I find myself in.
scottwio commentedon Oct 14, 2022
Find myself in the same issue, third party so can't move to object
wesbos commentedon Jan 25, 2023
Running into this with Express - though I can say it might just be their Typings because I've never needed this before.
I want to extend their Request and have to use something like this:
callumacrae commentedon Jun 14, 2023
same issue here!
current code:
would love:
roryabraham commentedon Jan 30, 2024
This would be cool – I naïvely requested this feature in type-fest as syntactic sugar to allow the
Mergefunction to merge N types without nesting:somebody1234 commentedon Jan 30, 2024
Rory Abraham (@roryabraham) nope - this kind is 100% possible. just:
unknown,never, or a customunique symbolused as a sentinel value.and that's it
(what this proposal would be adding is the ability to bundle up the array of parameters and pass the array around)
immjs commentedon Aug 23, 2026
I believe this would also be useful to do some meta-programming, where in my case, I am taking a class constructor and extending it within a function. This would allow me to extract all the type parameters from the input constructor, and apply them to the output constructor.