I am creating a helper function to create async reducers. I want to create a method which takes in a record (object) of functions, and returns a fully typed result.
Here is a short version of what I have so far:
const typed = <T extends keyof any>(
asyncActions: Record<T, (...args: any[]) => Promise<unknown>>
) => asyncActions;
const result = typed({
func: (praram: string) => Promise.resolve(),
func2: (praram: number) => Promise.resolve(),
});
The resulting type of result
is: const result: Record<"func" | "func2", (...args: any[]) => Promise<unknown>>
.
As you can see the keys of the return value are being infered correctly, but I cannot work out how to force the infer of the functions. Is this at all possible? Or am I barking up an extremely tall tree?