Ran into TS2589 and was able to distill it down to a very concise case. I'm trying to determine if there really is an infinite recursion case here or if the compiler may be missing a path to stop recurring. I think it's the latter.
It would make sense that while instantiating Proxied<Session> that remote causes recursion if the transformation type didn't filter out everything except properties which have the PromiseFunction type.
What do you think? Something worth bringing to the TS github, or would you think this is expected behavior? If so, how might you work around it, short of a ts-ignore.
type PromiseFunction = (...args: any[]) => Promise<any>;
type Proxied<T> = { [P in keyof T as T[P] extends PromiseFunction ? P : never]: T[P] };
class Session {
async getLocalService(name: string) {
return null as any;
}
get remote(): Proxied<Session> { return null as any; } // If this is removed, recursive instantiation doesn't happen
}
let remote: Proxied<Session>;
let func = remote.getLocalService; // Type instantiation is excessively deep and possibly infinite.(2589)
Playground is below.