Consider the following code snippet:
function test<T extends unknown[]>(source: [...T], b: T) {
return b;
}
const arg = [1, 'hello', { a: 1 }]
const res = test(arg, [])
const res1 = test([1, 'hello', { a: 1 }], [])
The variable res
has type
(string | number | {a: number;})[]
, while res1
has type [number, string, {a: number;}]
.
It is intriguing why the type inference for T
resulted in two different types.