Highlighted below is the code snippet:
declare function test1<T extends unknown[]>(value: T): T
const res1 = test1([1, 2, 3]) // type is number[]
declare function test2<T extends unknown[]>(value: [...T]): T
const res2 = test2([1, 2, 3]) // type is [number,number,number]
Upon examination, it's noticeable that by utilizing the ... separator operator
, a completely different result type is obtained. This raises questions about whether [...T]
holds the same properties as T
, given that T inherits an array structure.
Need to consider whether this distinction is a noteworthy trait to contemplate moving forward.