-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
overloads parameters union returntype
π Version & Regression Information
I tried v3.3.3333, v5.9.3 and nightly (Currently v6.0.0-dev.20260114), the problem occurred
β― Playground Link
π» Code
type obj1 = { a: { b: 1 } | { b: 2 } };
type expected1 = 1 | 2; // (Ok)
type result1 = obj1["a"]["b"];
// ^? type result1 = 1 | 2
type obj2 = { f(n: "number"): number, f(s: "string"): string };
type expected2 = number | string;
type result2 = ReturnType<obj2["f"]>;
// ^? type result2 = string
type expected3 = [n: "number"] | [s: "string"];
type result3 = Parameters<obj2["f"]>;
// ^? type result3 = [s: "string"]
type expected4 = number | string;
type result4 = obj2["f"] extends (...args: any[]) => infer U ? U : never;
// ^? type result4 = stringπ Actual behavior
When inferring the parameters or the return type of a callable type with more than one signature, only the last overload is taken into account
π Expected behavior
Every overload should be taken into account, and the inferred value should be the union of all the possible ones
Additional information about the issue
Could be somewhat related to #14107
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created