然后,属性在void类型上不存在,打字稿错误 [英] property then does not exist on type void , A typescript error
本文介绍了然后,属性在void类型上不存在,打字稿错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
reset(){
let alert = this.AlertCtrl.create({
buttons :['ok']
});
this.userservice.passwordreset(this.email).then((res: any)=>{
if(res.success){
alert.setTitle('Email sent');
alert.setSubTitle('please follow the instructions in the email to reset the password')
}
else{
alert.setTitle('failed');
}
})
}
错误:
属性然后不存在于void类型,打字稿错误
property then does not exist on type void , A typescript error
有人可以通过更正此代码段来帮助我,以便使'then'功能起作用 欢呼!
can someone please help me by correcting this code snippet so that the 'then' function works cheers!
推荐答案
此处的问题与passwordreset()
函数有关,
The issues here is with passwordreset()
function ,
它应该看起来像这样:
passwordreset(): Promise<any> {
// this should return a promise
// make sure , you are returning promise from here
return this.http.get(url)
.toPromise()
.then(response => response.json().data)
.catch(this.handleError);
}
您正在返回promise函数中的promise,但是没有返回 从
passwordreset()
返回它,
You were returning the promise inside promise function , but not returning it from
passwordreset()
,
请查看您的代码和更新后的代码,您将获得一个想法
Please have a look at your code and updated code , you will get an idea
您的代码:
passwordreset(email)
{
var promise = new Promise((resolve,reject)=>{
firebase.auth().sendPasswordResetEmail(email).then(()=>{
resolve({success :true});
})
.catch((err)=>{
reject(err);
})
return promise;
});
}
更新的代码:
passwordreset(email): Promise<any>
{
return new Promise((resolve,reject)=>{
firebase.auth().sendPasswordResetEmail(email).then(()=>{
resolve({success :true});
})
.catch((err)=>{
reject(err);
});
});
}
这篇关于然后,属性在void类型上不存在,打字稿错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文