在这里,我得到一个错误的NEWUSERthis.userObj.assigned_to.push(newUser);
为argument of type 'any' is not assignable to parameter of type 'never' typescript solution
我如何声明newUser摆脱错误?
感谢您的帮助。
addSubData(user: any) {
let i: any;
i = document.querySelectorAll('input[type="checkbox"]:checked');
for(var checked of i) {
const newUser = Object.assign({}, user)
newUser.dl = checked.value;
newUser.sub_impact = "Applicable";
newUser.co_score = "Added";
this.userObj.assigned_to.push(newUser);
}
this.commonService.updateUser(this.userObj).subscribe(()=> {
this.getLatestUser();
});
}
您的代码看起来像是错过了定义足够的类型的工作,因此很难为您提供一种最佳的修复方法(显然,最佳的方法是为您定义的内容(例如,类成员)填写类型)。
反正在这里的错误是莫名其妙的阵列assigned_to
已经被传递never
类型为每个成员类型,但现在你传递any
的类型。
你可以投newUser
的any
类型,never
类型会解决这个问题:
this.userObj.assigned_to.push(newUser as never);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句