Typescript Ionic 4在http请求调用返回的对象键上抛出错误
所以我有这样的函数Typescript Ionic 4在http请求调用返回的对象键上抛出错误,typescript,ionic-framework,ionic4,Typescript,Ionic Framework,Ionic4,所以我有这样的函数 if (form.valid) { this.api.resetPassword(this.otpcode).subscribe(response => { if (response.success) { this.showToast(response.message); this.router.navigateByUrl("/login"); } if (respons
if (form.valid) {
this.api.resetPassword(this.otpcode).subscribe(response => {
if (response.success) {
this.showToast(response.message);
this.router.navigateByUrl("/login");
}
if (response.error) {
this.showToast(response.error);
} else {
this.errors = response.errors;
}
});
}
}
但是,在VS代码中,我在尝试获取响应的行上遇到了一个错误,例如response.success
,表示类型“Object | any[]”上不存在属性“success”。
类型“Object”.ts(2339)
上不存在属性“success”。
我认为这只是一个VS代码错误,即使在运行ionic cordova build之后,控制台中也会出现相同的错误。因此,我首先添加了一个导出的变量,并在尝试访问属性之前将响应传递给它 i、 e 那我会的
onVerify(form: NgForm) {
this.submitted = true;
if (form.valid) {
this.api.resetPassword(this.otpcode).subscribe(response => {
this.response = response;
if (this.response.success) {
console.log(response);
this.showToast(this.response.message);
this.router.navigateByUrl("/login");
}
if (this.response.error) {
this.showToast(this.response.error);
} else {
this.errors = this.response.errors;
}
});
}
}
因此,我首先添加了一个导出变量,并在尝试访问属性之前将响应传递给它 i、 e 那我会的
onVerify(form: NgForm) {
this.submitted = true;
if (form.valid) {
this.api.resetPassword(this.otpcode).subscribe(response => {
this.response = response;
if (this.response.success) {
console.log(response);
this.showToast(this.response.message);
this.router.navigateByUrl("/login");
}
if (this.response.error) {
this.showToast(this.response.error);
} else {
this.errors = this.response.errors;
}
});
}
}
您是否可以共享您的响应对象请记录响应详细信息您是否可以共享您的响应对象请记录响应详细信息