Here is the code:
const arr = [1,2,3]
const res1 = arr.slice()
const res2 = Object.assign([],arr)
If I do a shallow clone with arr.slice()
, then I will get a new array res1
of type number[]
, which is the same as arr
. But if I do that with Object.assign()
, what I get is an array res2
of type never[] & number[]
.
Why the types of res2
will contain the type never[]
? And how could it be the type of number[]
while it also be the type of never[]
(by &
)?