错误 TS2339:属性 'sendEmailVerification' 在类型 'Promise<User>' 上不存在
error TS2339: Property 'sendEmailVerification' does not exist on type 'Promise<User>'
所以我正在开发我的 ionic4 应用程序,但在 sendEmailVerification 函数中出现错误。控制台问我是否忘记使用'await'。有什么解决办法?谢谢。
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);
}
}
}
好像currentUser
是一个promise,所以解决办法大概是:
...
await (await this.angularFireAuth.currentUser).sendEmailVerification();
...
请注意,仅当 sendEmailVerification
returns 承诺时才需要外部 await
,并且您需要等待它完成才能返回结果。
所以我正在开发我的 ionic4 应用程序,但在 sendEmailVerification 函数中出现错误。控制台问我是否忘记使用'await'。有什么解决办法?谢谢。
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);
}
}
}
好像currentUser
是一个promise,所以解决办法大概是:
...
await (await this.angularFireAuth.currentUser).sendEmailVerification();
...
请注意,仅当 sendEmailVerification
returns 承诺时才需要外部 await
,并且您需要等待它完成才能返回结果。