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
interfaceX{a(x: string): void;a(x: number): void;}typeT=Parameters<X["a"]>[0];letn: T=1;// workslets: T="a";// ERROR: Type 'string' is not assignable to type 'number'
π Actual behavior
When using the Parameters<T> helper type on a function with overloads, the resulting type considers only the very last overload.
I noticed this while trying to extract tpe type of the second argument of String.replace which can be both a string and a replacer function; only the replacer function is seen.
π Expected behavior
I would expect the previous code to consider valid all types which can be used for the function's parameters.
In the given example T should be resolved as string | number.
Bug Report
π Search Terms
Parameters, Overload
π Version & Regression Information
5.0.4
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
When using the
Parameters<T>helper type on a function with overloads, the resulting type considers only the very last overload.I noticed this while trying to extract tpe type of the second argument of
String.replacewhich can be both a string and a replacer function; only the replacer function is seen.π Expected behavior
I would expect the previous code to consider valid all types which can be used for the function's parameters.
In the given example
Tshould be resolved asstring | number.Possibly related to #53541