I encountered a compile error that I can't quite figure out. (Just to clarify, this issue only occurs in TS 2.4.1, while TS 2.3.4 works perfectly fine.) Below is a sample code snippet showcasing the compile error. Although creating an overload is not recommended in this scenario and using a union type for the function signature would be more appropriate, I chose to stick with a simpler example to highlight the problem:
class Animal {
a: string;
}
class Dog extends Animal {
b: string;
}
function test(func: (p: Dog) => any): any;
function test(func: (p: Animal) => any): any;
function test(func: (p: Animal) => any): any {
return undefined;
}
The compiler throws a TS2394 error:
Overload signature is not compatible with function implementation
This error specifically occurs at:
function test(func: (p: Dog) => any): any;
The error can be resolved by adjusting the function definition as follows:
function test(func: (p: any) => any): any {