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
Search Terms: rest tuples function parameters arguments
Code
// Gets the parameters of a function type as a tupletypeParameters<Textends(...args: any[])=>any>=Textends(...args: infer U)=>any ? U : never;// Removes the first element from a tupletypeTail<Textendsany[]>=((...args: T)=>any)extends((head: any, ...tail: infer U)=>any) ? U : never;// Example function typetypeMyFunctionType=(foo: number,bar: string)=>boolean;// Note that when we write this type out explicitly, we get the correct resulttypeExplicit=(...args: Tail<Parameters<MyFunctionType>>)=>ReturnType<MyFunctionType>;// (bar: string) => boolean// But when we try and genericize the above and just pass in the function type, we get a different resulttypeBind1<Textends(head: any, ...tail: any[])=>any>=(...args: Tail<Parameters<T>>)=>ReturnType<T>;typeGeneric=Bind1<MyFunctionType>;// (...args: any[]) => boolean
Expected behavior:
The explicit definition (type Explicit) should result in the same type as the generic definition (type Generic).
Actual behavior:
The generic definition discards the function parameter data.