I need TypeScript to correctly infer the type T in the return value of my "wrongInference" function.
interface Foo {
bar: string;
}
const paramFunction = (bar: string): Foo => ({
bar
});
type GenericFunction<T> = (...args: any) => T;
export const wrongInference = <T, F extends GenericFunction<T>>(
paramFunction: F
) => ({
data: {} as T,
});
const wrongType = wrongInference(paramFunction);
TypeScript infers the data value as unknown. Is there any way around this?

Here is how you could fix your problem with a conditional return type and the
inferkeyword:TypeScript playground