-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Overload Signature Is Not Compatible For Inherited Type Function Parameter #17162
Comments
This looks like intended behavior. Since the The type of Let's call That is: function test(func: (p: Dog) => any): any;
function test(func: (p: Animal) => any): any;
function test(func: (p: Dog) => any): any { // no error now |
Ahh, so I confused a "callback parameter" with the return type. Since func is a call back function, it's type is a call back parameter? Side note, I would expect this to give a different error function test(func: (p: Dog) => any): any;
function test(func: (p: Animal) => any): any;
function test(func: (p: Animal|Dog) => any): any { because func: (p:Animal) doesn't accept a Dog. Never-mind, it's the same issue and I see that now. This is what I want: function test(func: (p: Dog) => any): any;
function test(func: (p: Animal) => any): any;
function test(func: ((p: Animal) => any) | ((p:Dog) => any)): any { |
Note that |
@jcalz I noticed that. Ended up with something like this: function test<T,A extends Dog >(animal:A, func: (p: A) => T): T;
function test<T,A extends Animal>(animal:A, func: (p: A) => Foo<T>): Foo<T>;
function test<T,A extends Animal>(animal:A, func: (p: A) => T|Foo<T>): T|Foo<T> {
return func(animal);
} I've included I'm guessing that is the best way? |
Crosspost reference https://stackoverflow.com/questions/45087264/how-to-cleanly-write-a-typescript-function-with-different-callback-overload-para for anyone who ends up here |
TypeScript Version: 2.4.1
Code
Expected behavior:
No TS2394 Compiler error
Actual behavior:
a TS2394 Compiler error for this line:
Changing function definition the below resolves the compile error:
The text was updated successfully, but these errors were encountered: