typescript - 类型 'accessToken' 上不存在属性 'AuthCredential'

标签 typescript firebase firebase-authentication angularfire2

通过运行 ionic serve 我得到以下错误:

Property 'accessToken' does not exist on type 'AuthCredential'.
// You can use it to access the Google API.
let token = result.credential.accessToken;

我已经将我的 firebase 从 firebase: ^4.12.1 更新到 firebase: ^5.5.9

这是我的 ionic 信息输出

Ionic:

   ionic (Ionic CLI)  : 4.1.2
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.9

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : no whitelisted plugins (19 plugins total)

System:

   NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)
   npm    : 5.8.0
   OS     : Windows 10

这是auth.service.ts

中的方法
signInWithGoogle() {
   console.log('Sign in with google');
   return this.oauthSignIn(new firebase.auth.GoogleAuthProvider());
}

private oauthSignIn(provider: AuthProvider) {
   if (!(<any>window).cordova) {
        return this.afAuth.auth.signInWithPopup(provider).then(() => {
            this.saveUserDetails('gmail');
        });
   } else {
       return this.afAuth.auth.signInWithRedirect(provider)
           .then(() => {
              return this.afAuth.auth.getRedirectResult().then(result => {
                 // This gives you a Google Access Token.
                // You can use it to access the Google API.
                let token = result.credential.accessToken;
               // The signed-in user info.
                let result_user = result.user;

                this.saveUserDetails('gmail');

                console.log(token, result_user);
      }).catch(function (error) {
         // Handle Errors here.
         alert(error.message);
      });
   });
  }
}

为什么 AuthCredential 对象上不存在 accessToken 属性?

最佳答案

您需要将 AuthCredential 转换为具有 accessToken 属性的 OAuthCredential:https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth-types/index.d.ts#L244

关于typescript - 类型 'accessToken' 上不存在属性 'AuthCredential',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53458622/

相关文章:

javascript - Typescript 找不到导入的模块

javascript - AngularFire(Angular + Firebase)身份验证错误延迟

javascript - Firestore 身份验证,使用用户 UID 与 ionic 文档 ID

firebase - Web 应用程序中出现意外的 firebase.auth().currentUser.uid

javascript - 使用某种函数式编程将一个对象映射到另一个对象

TypeScript 不应发出类型引用

javascript - Typescript 认为响应数组是一个对象

firebase - (Flutter Web) Firebase 存储不适用于 firebase 插件

android - Firebase ML-Kit 多检测器

javascript - 根据值从 Firebase JSON 树获取特定值