Closed
Description
Bug Report
π Search Terms
Parameters, Overload
π Version & Regression Information
5.0.4
β― Playground Link
Playground link with relevant code
π» Code
interface X {
a(x: string): void;
a(x: number): void;
}
type T = Parameters<X["a"]>[0];
let n: T = 1; // works
let s: 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
.
Possibly related to #53541