-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function overload breaks generics #29312
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Comments
I have same issue in another example (TypeScript version: 3.2.2) function foo(a: number, b: string): void;
function foo(a: string): void;
function foo(a: string | number, b?: string) {}
foo.call(null, 1, "2"); // Expected 2 arguments, but got 3.
foo.bind(null)(1, "2"); // Expected 1 arguments, but got 2.
foo.apply(null, [1, "2"]); // Type 'number' is not assignable to type 'string'.
foo.call(null, "2"); // no errors
foo(1, "2"); // no errors
foo("2"); // no errors So I can't use Update: Sorry, I didn't see #27028 (comment) |
function Wrap<O extends (...any) => any>(a: O, params: Parameters<O>): void { }
let Bar: {
Foo<K extends "FooBar">(a: K, b: number): void;
//comment out this ↓ line:
Foo(a: never): never;
};
//This should work:
Wrap(Bar.Foo, ["FooBar", 78]) |
Inference only works with the last overload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript Version: 3.1.6
Search Terms: overload function generic
Code
The text was updated successfully, but these errors were encountered: