I have a function that accepts a generic type arguments, and returns a tuple of arrays of the same types, however this function can accept dynamic amount of those generics. Something like:
function myFunction<T1>(): [Array<T1>] {...}
function myFunction<T1, T2>(): [Array<T1>, Array<T2>] {...}
function myFunction<T1, T2, T3>(): [Array<T1>, Array<T2>, Array<T3>] {...}
and so on.
How do I define a single generic type T and equivalent return value so that I can pass as many different generic as I want?
I have tried doing it in a simple way like:
function myFunction<T extends any[]>(): Array<Array<T[number]>> {...}
However that loses information on what type is stored at which index.
I also tried something similar to this:
function myFunction<T extends any[]>(): {[key in keyof T]: Array<T[key]>} {...}
However calling keyof T on an Array returns other properties besides indexes like "length" etc. which also makes it a little problematic during assignment. Resulting in errors similar to this:
TS2322: Type 'string[][]' is not assignable to type '{ [x: number]: string[]; length: string[]; toString: string[]; toLocaleString: string[]; pop: string[]; push: string[]; concat: string[]; join: string[]; reverse: string[]; shift: string[]; slice: string[]; sort: string[]; splice: string[]; ... 25 more ...; at: string[]; }'.