I am working on an interface with the following structure:
interface Res<R = any> {
first?(): Promise<R>;
second(arg: { response: R }): void;
}
However, I noticed that when creating a plain object based on this interface, the response type is not inferred correctly. Here's an example:
const entity: Res = {
first: () => Promise.resolve({ name: 'Bob' }),
second: (arg) => {
console.log(arg.response) // currently inferred as "any", but should be "{ name: string }"
}
}
Is it feasible to obtain the correct type for arg.response
based on the return value of the first()
method?