Closed
Description
TypeScript Version: 3.1.0-dev.20180821
Search Terms: function argument infer overload return type rest tuple
Code
function foo (a: string): string;
function foo (a: number, b: string): boolean;
function foo (a: boolean, ...b: object[]): object;
function foo (...args: any[]): any {
}
type A = ReturnType<typeof foo>;
Expected behavior:
Type A
is a union of the return types of every overload, or an error along the lines of "cannot infer things about an overloaded function" is generated.
Actual behavior:
Type A
is object
.
This also happens when inferring function params:
type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer U) => any ? U : never;
type B = Parameters<typeof foo>; // [boolean, ...object[]]
Playground Link: