Code:
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');
}
})
}
Error:
property then does not exist on type void , A typescript error
can someone please help me by correcting this code snippet so that the 'then' function works cheers!
The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names. Copied!
The "Type 'void' is not assignable to type" TypeScript error occurs when we forget to return a value from a function, so the function gets an implicit return type of void . To solve the error, make sure you return a value of the correct type from your functions before the assignment.
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the string type. To solve the error, use an object instead of a string, or make sure you're accessing a valid built-in method on the string.
The issues here is with passwordreset()
function ,
It should look like this :
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);
}
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
Your code :
passwordreset(email)
{
var promise = new Promise((resolve,reject)=>{
firebase.auth().sendPasswordResetEmail(email).then(()=>{
resolve({success :true});
})
.catch((err)=>{
reject(err);
})
return promise;
});
}
Updated Code :
passwordreset(email): Promise<any>
{
return new Promise((resolve,reject)=>{
firebase.auth().sendPasswordResetEmail(email).then(()=>{
resolve({success :true});
})
.catch((err)=>{
reject(err);
});
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With