Is there a way in Typescript to reference a function type with generics without instantiating them, but rather passing them to be instantiated when the function is called?
For instance, consider the following type:
type FetchPageData<T> = (client : APIClient<T>) => T;
where APIClient is an abstract class defined as follows:
export abstract class APIClient<T> {
abstract getData(demoDataIsSelected : boolean, queryParameters ?: ApiQueryParameters) : T;
}
If I try to create a function of this type like this:
fetchPageData : FetchPageData = client => {
return client.getData(x, y);
}
Typescript will prompt me to provide the generic type for T. My intention is to reference the type definition without needing to specify the T, as it only matters during the function call.
If this approach doesn't work, what would be the syntax for obtaining a value for T and passing it to FetchPageData upon instantiation? (This must be done using const syntax due to assigning with useCallback in React)