Need help understanding how the below piece of code works.
function concatFun<T extends any[], U extends any[]>(
arg1: T[],
arg2: U[]
): [...T, ...U] {
const newArr = [...arg1, ...arg2]; // (T | U)[]
return newArr; // error Type '(T | U)[]' is not assignable to type '[...T, ...U]'.
// Target requires 2 element(s) but source may have fewer.
}
I wanted the return type to be [...T, ...U], but the return type is (T | U)[].