Is there a way to modify this function that accepts generic rest parameters to also accept an array parameter without using the spread operator? This would make chaining things much clearer:
function fn<T>(...args: T[]): Something<T> {
}
let something = fn(1, 2, 3, 4); // all good.
When passing an array as a parameter, the return type becomes Something<T[]>
. However, I want the return type to be Something<T>
.
let something: Something<number> = fn([1, 2, 3, 4]);
I am looking for a way to achieve a type similar to:
(arg T) | (...args T[])
Not sure how to make it happen yet.