I have a function that receives args that can be either typed as string or as [string, Record<string, string>].
This function returns an object for which the keys are either the args of the function if these args are typed string or the first string in the array if these arg are typed [string, Record<string, string>]. All the values of this object are typed as string
For example :
exampleFunction("test1", "test2", ["test3", { result: "randomstring" }], "test4");
should return something typed like this:
type tResult = {
test1: string;
test2: string;
test3: string;
test4: string;
};
This function can take any amount of args and any of those args can be either string or [string, Record<string, string>].
The challenge is to type the returnType of this exampleFunction.
I tried to type it tExampleFunctionReturn<T> with:
type tExampleFunctionReturn<T extends tExampleFunctionArgs> = Record<
T[number] extends string ? T[number] : T[number][0],
string
>
But it does not work.
Can someone please help me ? Thank you for your answer.