How come ReturnType<Generic> is only accurate when the target generic doesn't receive args?
const MakeGeneric = <
A extends (...args: any[]) => any,
B extends A extends undefined ? (...args: any[]) => any : (args: ReturnType<A>) => any,
>(args: { a?: A, b?: B }) => {}
MakeGeneric({
a: () => 'string',
b: (args) => '', // CORRECT: args is "string"
})
MakeGeneric({
a: (args) => 'string',
b: (args) => '', // INCORRECT: args is "any"
})
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
