类型“ void”不存在属性“ sendEmailVerification”

时间:2018-10-14 00:10:08

标签: javascript typescript email ionic-framework firebase-authentication

无论我将promise放在哪里,我都尝试发送电子邮件验证,然后将data.uid设置为user.id。

这是我的代码

onCreate(form: NgForm) {
var user = new User();
user.name = form.value.name;
user.email = form.value.email;
user.contact = form.value.contact;
if(form.value.gender == "male") {
  user.gender = "male";
} else {
  user.gender = "female"
}
let loading = this.mProv.getLoader('Creating your account...', 0);
loading.present();
var promise = this.afAuth.auth.createUserWithEmailAndPassword(form.value.email, form.value.password)
  .then(data => {
    user.id = data.uid;
    this.userProvider.addUser(user)
      .then(_ =>
        loading.dismiss()
      )
      .catch(error => {
        console.log(error);
        loading.dismiss();
        this.mProv.showAlertOkMessage('Error','Sign up error. Please try again later.');
      });
  })
  .catch(error => {
    console.log(error);
    loading.dismiss();
    this.mProv.showAlertOkMessage('Error','Sign up error. Please try again later.');
  });
  promise.then(function(user) {
    user.sendEmailVerification();

    // firebase.auth().currentUser.sendEmailVerification();

  }, function(error) {
    console.log(error)
  })
}

错误消息= Property 'sendEmailVerification' does not exist on type 'void'.

enter image description here

如果我在.createUserWithEmailAndPassword之后许诺

错误消息= Property 'uid' does not exist on type 'void'.

enter image description here

1 个答案:

答案 0 :(得分:1)

Typescript抱怨uid在void类型上不存在,请尝试按以下方式更改它,

.then((data:any)=>{
   user.id = data.uid;
}