Let's consider the following scenario:
type AnyFunction = (...args: any[]) => any;
abstract class Foo<F extends AnyFunction> {}
class Bar extends Foo<() => string> {}
In addition, there is a function like this:
function foo<F extends AnyFunction>(foo: Foo<F>): void {}
When calling foo()
, the desired outcome is to have accurate type inference. For instance, when invoking foo(new Bar())
, the expected result would be for the type () => string
to be inferred as the generic parameter T</code in <code>foo
. However, TypeScript defaults to using AnyFunction
, which is the least specific type.
Is there a way to resolve this issue? The goal is to maintain the ability to call foo()
accordingly while ensuring that T
is correctly inferred as () => string
.