function generate<P extends object>(init: (p: P) => void) {
return function (p: P): P {
init(p)
return p
}
}
const g = generate(function AAA<T>(p: T) {
console.log(p)
})
const result = g({
x: 1
})
result.x // TS2339: Property 'x' does not exist on type '{}'.
The generate function is a higher order function and it seems typescript can't deduce the generic type P.
How can I make generate able to accept a generic typed function as parameter?