I have a bulk of generated functions with different amount and types of arguments. Like this:
function f(a: string, b: number): number;
function f1(a: number): string;
function f2(a: boolean): void;
// etc...
I need to wrap them like this:
function myF(a: MaybeRef<string>, b: MaybeRef<number>): number;
function myF1(a: MaybeRef<number>): string;
function myF2(a: MaybeRef<boolean>): void;
// etc...
How can I achieve this?
I've tried something like:
type MaybeRefParameters<T extends (...args: any) => any> = T extends (
...args: infer P
) => any
? MaybeRef<P> // <-- It wraps all arguments, not individual
: never
function my<F extends (...data: any) => any>(f: F): ReturnType<F> {
return (...args: MaybeRefParameters<F>) => f(args.map(unref))
}
const myF = my(f)
const myF1 = my(f1)
const myF2 = my(f2)
But it does not work.
unrefandMaybeRefmight look like, and also what "it does not work" might mean (that is, "It wraps all arguments"). If I made mistakes in my guesses, please consider modifying the code here to constitute a minimal reproducible example suitable for demonstrating the issue.