deepCopy2(source: T, target?: T): T {
target = target || new source.constructor();
for ( const i in source) {
if (typeof source[i] === 'object') {
target[i] = (source[i].constructor === Array) ? [] : new source[i].constructor();
this.deepCopy2(source[i], target[i]);
} else {
target[i] = source[i];
}
}
return target;
}
new source.constructor()和new source[i].constructor();报错
TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
其类型缺少调用或构造签名的表达式无法使用 "new"
但是如果用any代替泛型就不会报错,但是如果一定要用泛型怎么解决这个问题????