使用Facebook身份验证登录时出现Typescript编译器错误。
Facebook认证工作正常。
只是typescript编译器不喜欢这个响应。
typescript编译器错误为:“firebaseauthdata类型上不存在属性‘facebook’。”
这是我的代码:

 public loginWithFacebook():void{
         this.ref.authWithOAuthPopup("facebook", function(error, authData?)          {
      if (error) {
        console.log("Login Failed!", error);
      } else {

            //Error here - Doesnt like authData.facebook.
            let user = {
              email    : authData.facebook.email,
              password : null,
              uid: authData.uid
            }

            this.addUser(user);
      }
    });
}

在authdata.facebook.email的回复中,错误似乎是。
这段代码运行良好。
但不是typescript编译器。
我需要转到:authdata.facebook才能访问电子邮件字段,但typescript似乎与facebook是什么混淆了。

最佳答案

所以问题是主firebase.d.ts文件已过期。在2.0.2版上。它需要纠正(我可能会发送公关)。
但现在您可以将此添加到firebase.d.ts文件中以进行移动。

interface FirebaseAuthData {
    uid: string;
    provider: string;
    token: string;
    expires: number;
    auth: Object;
    google?: FirebaseAuthDataProvider;
    facebook?: FirebaseAuthDataProvider;
}

interface FirebaseAuthDataProvider {
    accessToken: string;
    cachedUserProfile: any;
    displayName: string;
    email?: string;
    id: string;
    profileImageURL: string;
}

这将更新接口以便编译工作。

关于facebook - 使用Facebook身份验证登录时出现Typescript编译器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34025060/

10-16 19:35