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.
This is a design limitation and working as intended. Parameters<> is a conditional type using type inference, and these have trouble with overloads. See Inferring Within Conditional Types:
When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the last signature (which, presumably, is the most permissive catch-all case). It is not possible to perform overload resolution based on a list of argument types.
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.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 asstring | number
.Possibly related to #53541
The text was updated successfully, but these errors were encountered: