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
"...args: infer" on an overloaded function chooses only one function head #26136
Mike North (@mike-north) is this a duplicate, though? #26132 doesn't have overloads, and arguments list inference of fn gives something similar to what you request here:
// sample from #26132typeRec={foo: (a: string,b: number)=>void,bar: (b: boolean,c: RegExp)=>void,}typeParameters<T>=Textends(...args: infer U)=>any ? U : never;declarevarfn: <KextendskeyofRec>(e: K, ...args: Parameters<Rec[K]>)=>void;// test parameter extractiontypetest=Parameters<typeoffn>;// type test = ["foo" | "bar", ...(string | number | boolean | RegExp)[]]
Discussed for a while yesterday. This looks reasonably straightforward if you're just capturing the entire parameter list into a single spread, but quickly turns into a bunch of really complicated questions once you do anything else
What would the behavior of type Args<F> = F extends (n: number, ...args: infer T) => any ? T : never; be? Would it be sound to just capture the matching overloads, or not?
What happens when you put T into a different argument list? Potentially a combinatorially explosive expansion in to overloads?
More problems I can't recall at the moment
Overall too complex unless there are some important use cases that appear.
Activity
mike-north commentedon Aug 2, 2018
Closing as duplicate of Brian Terlson (@bterlson)'s #26132
bterlson commentedon Aug 2, 2018
Mike North (@mike-north) is this a duplicate, though? #26132 doesn't have overloads, and arguments list inference of
fngives something similar to what you request here:mike-north commentedon Aug 2, 2018
Good catch, I must have read your issue too quickly. Maybe this should be un-tagged as duplicate
RyanCavanaugh commentedon Aug 7, 2018
Discussed for a while yesterday. This looks reasonably straightforward if you're just capturing the entire parameter list into a single spread, but quickly turns into a bunch of really complicated questions once you do anything else
type Args<F> = F extends (n: number, ...args: infer T) => any ? T : never;be? Would it be sound to just capture the matching overloads, or not?Tinto a different argument list? Potentially a combinatorially explosive expansion in to overloads?Overall too complex unless there are some important use cases that appear.
spiritwindy commentedon Aug 15, 2018
Ryan Cavanaugh (@RyanCavanaugh)
some example like
Function.prototype.call
Function.prototype.apply
Function.prototype.bind