I have an interface like this coming from an 3rd party lib:
MyInterface{
foo(arg: string): Promise<any>;
foo(arg: string, ...params: any[]): Promise<any>;
foo<T>(arg: string): Promise<T>;
foo<T>(arg: string, ...params: any[]): Promise<T>;
bar(arg: string, callback?: (err: Error, row: any) => void): Promise<number>;
bar(arg: string, ...params: any[]): Promise<number>;
}
And I want to delegate the interface methods to an implementation of the same type, like this:
MyClass implements MyInterface {
private impl:MyInterface = ...
foo(..) //how to do it right ??
// TS2393: Duplicate function implementation.
bar(arg: string, callback?: (err: Error, row: any) => void): Promise<number>{
return impl.bar(sql,callback);
}
// TS2393: Duplicate function implementation.
bar(arg, ...params: any[]): Promise<number>{
return impl.bar(arg,params);
}
}
I have no idea how to implement the delegation correctly, so the right impl
methods are called.
Neither TypeScript function overloading Nor Is there a way to do method overloading in TypeScript? is helping me to make the correct delegation.