【问题标题】:error TS2339: Property 'sendEmailVerification' does not exist on type 'Promise<User>'错误 TS2339:“Promise<User>”类型上不存在属性“sendEmailVerification”
【发布时间】:2020-12-01 00:14:51
【问题描述】:

所以我正在开发我的 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);
    }
  }
}

【问题讨论】:

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


    【解决方案1】:

    看来currentUser 是一个promise,所以解决方案大概是:

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

    请注意,仅当sendEmailVerification 返回一个promise 时才需要外部await,并且您需要等待它完成才能返回结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-23
      • 2019-04-11
      • 1970-01-01
      • 2020-07-27
      • 1970-01-01
      • 2019-01-21
      • 2016-08-13
      • 1970-01-01
      相关资源
      最近更新 更多