My goal is to dynamically define a deeply nested ReturnType for a function based on the number of arguments passed in the "rest" parameter. For example, if we have:
getFormattedDates(
dates: Date[],
...rest: string[] // ['AAA', 'BBB', 'CCC', etc...]
): Record<string, Record<string, Record<string,etc...>>>
The final nested object should be of type Record<string, Date[]>
. In case there is no second argument, the return type should simply be Date[]
.
I have searched online for a solution but couldn't find a satisfactory answer that explains the logic behind it. This is my first time asking a question, so I hope I've provided enough clarity.
If anyone could provide insight into this issue, I would greatly appreciate it. Thank you!