function concat1<T extends readonly any[], U extends readonly any[]>(arr1: T, arr2: U): [...T, ...U] {
return [...arr1, ...arr2];
}
function concat2<T extends readonly any[], U extends readonly any[]>(arr1: T, arr2: U) {
return [...arr1, ...arr2];
}
const x1 = concat1([1,2,3] as const, [4,5, 6] as const);
const x2 = concat2([1,2,3] as const, [4,5, 6] as const);
Here, TypeScript is okay with concat1 returning [...T, ...U], but instead infers the type of concat2 to be T[number][].
Notice U was not in the output type!
As a result, x1 has the type [1, 2, 3, 4, 5, 6] and x2 has the type (1, 2, 3)[]).