Looking for a solution to alter the return type of all functions within a class, while also maintaining generics.
Consider a MyService class:
class CustomPromise<T> extends Promise<T> {
customData: string;
}
interface RespSomething {
data: string;
}
interface RespWhatever {
data: number;
}
class MyService {
something(req: { x: string; y: string }): CustomPromise<RespSomething> {
return new CustomPromise<RespSomething>((res, req) => {});
}
whatever(req: { a: string }): CustomPromise<RespWhatever> {
return new CustomPromise<RespWhatever>((res, req) => {});
}
}
The goal is to convert the type to:
interface TransformedMyService {
something(req: { x: string; y: string }): Promise<RespSomething>;
whatever(req: { a: string }): Promise<RespWhatever>;
}
I am pondering whether this can be achieved in TypeScript.