Currently ts-auto-mock doesn't support method or function overload
As you can see in the example below calling mock.method with a number will return the return type of the first declaration method(a: string): void
instead of returning the type of the second declaration method(b: number): string;
This is happening because ts-auto-mock always use the first declaration of a method to decide the return value.
export interface Interface {
method(a: string): void;
method(b: number): string;
}
const mock = createMock<Interface>();
mock.method('aString') // will return void
mock.method(123) // will return void. It should return a string
To support method overload we need to understand the inputs given to a method/function and then decide what to return
We need to make sure that the proposal will not result in throwing an Error or impacting the performance
We would like to add this functionality without impacting any other functionalities like
It should be easy to extend the overload functionality later on without having to rewrite the entire architecture
The consumer of ts-auto-mock should not be presented with extra complexity when overloads is needed for their tests. They should be able to use createMock in the same way and they should be able to receive the expected value when calling the method with different parameters