错误TS2339:类型“ Promise <用户>”上不存在属性“ sendEmailVerification”

时间:2020-08-11 10:31:46

标签: angular typescript ionic-framework firebase-authentication angularfire2

所以我正在使用ionic4应用程序,并且 sendEmailVerification 函数出现错误。控制台问我是否忘记使用“等待”。有什么解决方案?谢谢。

import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';

@Injectable({
  providedIn: 'root'
})
export class FirebaseAuthService {

  constructor(private angularFireAuth: AngularFireAuth) { }

  async registerWithEmailPassword(email, password) {
    try {
      const result = await this.angularFireAuth.createUserWithEmailAndPassword(email, password);
      await this.angularFireAuth.currentUser.sendEmailVerification();
      return result;
    }catch (error) {
      throw new Error(error);
    }
  }
}

1 个答案:

答案 0 :(得分:1)

currentUser似乎是一个承诺,因此解决方案可能是:

...
      await (await this.angularFireAuth.currentUser).sendEmailVerification();
...

请注意,只有在await返回承诺并且您需要等待其完成之后才能返回结果,才需要外部sendEmailVerification