Return the same types as the passed array parameter

27 views Asked by At

After several hours of research I managed to create a function that returns an array with the same types as the passed parameter:

const parseItems = <T extends unknown[]>(items: [...T]): T => { ... }

const items = parseItems(['hello', 101, true]) // [string, number, boolean]

But how could I write the above code without using the spread operator? Something like this:

const parseItems = <T extends unknown[]>(items: T): ??? => { ... }
0

There are 0 answers