【问题标题】:Property 'uid' does not exist on type 'Promise<User>'.ts(2339)'Promise<User>'.ts(2339) 类型上不存在属性 'uid'
【发布时间】:2021-11-04 14:02:21
【问题描述】:

我在 vscode 中收到以下错误:

“Promise”类型上不存在属性“uid”.ts(2339)

我也遇到了与 updateProfile 相同的错误:

“Promise”类型上不存在属性“updateProfile”。

代码:

export class SignupPage implements OnInit {

  email: string;
  pwd: string;
  username: string;

  constructor(public fs: AngularFirestore, public af: AngularFireAuth, public nav: NavController) { }

  signup() {
    this.af.createUserWithEmailAndPassword(this.email, this.pwd).then(() => {
      localStorage.setItem('usesrid', this.af.currentUser.uid);
      this.af.currentUser.updateProfile({
        displayName: this.username,
        photoURL: ''
      }).then(() => {
        this.nav.navigateRoot('/tabs')
      }).catch(err => {
        alert(err.message)
      })
    }).catch(err => {
      alert(err.message)
    })
  }
}

我是 Typescript 的新手,所以我不太确定这个错误的原因可能是什么。
提前致谢。

【问题讨论】:

    标签: angular typescript ionic-framework firebase-authentication


    【解决方案1】:

    您的currentUser 似乎是一个承诺,因此您需要使用awaitthen 来获取实际用户:

    this.af.currentUser.then((user) => {
      user.updateProfile({
        ...
    

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 2019-08-11
      • 2021-08-02
      • 2020-06-02
      • 2022-07-09
      • 2022-10-04
      相关资源
      最近更新 更多