```
```### 问题描述
问题出现的环境背景及自己尝试过哪些方法
想用ts编写一个简单的深拷贝方法, 但是ts的类型校验不通过, 求大佬给解答下我这个错误怎么出现的, 应该怎么解决吖!!!!!
相关代码
function deepCopy (sourceData: T): T {
if (Array.isArray(sourceData)) {
return sourceData.map(item => deepCopy(item)) as T;
}
const obj: T = {} as T;
for(let key in sourceData) {
if ((typeof sourceData[key] === 'object') && sourceData[key] !== null) {
obj[key] = deepCopy(sourceData[key]);
} else {
obj[key] = sourceData[key];
}
}
return obj;
}
粘贴代码文本(请勿用截图)
你期待的结果是什么?实际看到的错误信息又是什么?
Conversion of type 'any[]' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. 'T' could be instantiated with an arbitrary type which could be unrelated to 'any[]'
这样可?