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
typeArgumentsType<Textends(...args: any[])=>any>=Textends(...args: infer R)=>any ? R : any[];
Currently the compiler complains that rest parameters have to be an array type, but if the full type of the rest parameters could be inferred (as a tuple), then you could extract the type of the parameters of a function, allowing you to do something like this:
@s-ve Thanks for that. It looks like it does cover this usage, but my suggestion should be far easier to implement, because it doesn't require an additional kind of types.
Also, I'm not sure variadic kinds are needed to specify a tuple, since the type of rest parameters is already a tuple, so T should be enough (instead of ...T), as long as T is a tuple. They would be needed however to specify types of arbitrary length.
// For example, you don't need variadic kinds for this:functionf(...rest: [number,string]) : void;// But you need for this:functionf(...rest: [number,string, ...boolean]) : void;
With the above examples in mind, it becomes obvious that you don't need variadic kinds for the type inference of rest parameters, because at the time when the inference is done, the tuple is already known.
Edit, I'd also like to link this here, which proposes a similar thing: #5331
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Search Terms
rest parameters infer conditional types
Suggestion
Allow type inference for rest parameters:
Currently the compiler complains that rest parameters have to be an array type, but if the full type of the rest parameters could be inferred (as a tuple), then you could extract the type of the parameters of a function, allowing you to do something like this:
Furthermore, allowing the rest parameters to have a type, would then allow typed forwarding:
The text was updated successfully, but these errors were encountered: