The question is how to describe the **return type** of function **bar** which should be the result of execution of generic function **fn**.

`function foo(fn<T>) /*return →*/ function bar<B> /*return →*/ call fn<B>()`

Example:

```
function foo<T extends <X>(...args: any) => any>(fn: T) {
    return function bar<B>(): ReturnType<typeof fn> /***/ {
        return fn<B>({ /*config*/ });
    }
}

{
    const f1 = <T>() => Promise.resolve(({/*input*/ } as T));
    const x1 = foo(f1)
    const y1 = x1<{ a: 'A' }>()/**Promsise<unknown>❌*/.then(data => data.a); // should be Promise<{ a: 'A'}> ✅
    const y12 = x1<{ b: 'B' }>()/**Promsise<unknown>❌*/.then(data => data.b); // should be Promise<{ b: 'B'}> ✅
}

{
    const f2 = <T>() => ({/*input*/ } as T);
    const x2 = foo(f2)
    const y2 = x2<{ a: 'A' }>()/**unknown❌*/.value // should be { a: 'A'} ✅
    const y21 = x2<{ b: 'B' }>()/**unknown❌*/.value // should be { b: 'B'} ✅
}

```

Thanks 

**Update 1** :

TypeScript related issues

* <https://github.com/microsoft/TypeScript/issues/37181>
* <https://github.com/microsoft/TypeScript/issues/40542>