自从迁移到 ESLint 以来,我一直收到以下突出显示的错误消息:
facebookSignIn(course?: ICourse): Promise<void> {
const provider = new firebase.auth.FacebookAuthProvider();
return this.afAuth
.signInWithPopup(provider)
.then(async (result: UserCredential) => {
if (result.user) {
const doc = await this.firebaseService.docExists(`/users/${result.user.uid}/`);
if (!doc && result.additionalUserInfo?.profile) {
const user: IUser = {
uid: result.user.uid,
email: result.user.email,
displayName: result.user.displayName,
photoURL: result.user.photoURL,
};
await this.userService.processNewUser(
user,
// Element implicitly has an 'any' type because expression of type '"first_name"' can't be used to index type 'Object'.
result.additionalUserInfo.profile['first_name'],
// Element implicitly has an 'any' type because expression of type '"last_name"' can't be used to index type 'Object'.
result.additionalUserInfo.profile['last_name']
);
}
if (course) {
this.builderSignIn(course, result.user.uid);
}
}
})
.catch((error: { message: string }) => {
this.toastrService.warning('Something has gone wrong. Please try again.', 'Oops!');
this.logger.debug('An error occurred during Facebook Sign In');
this.logger.error(error.message);
throw error;
});
}
我在 Firebase 中查找了 AdditionalUserInfo 的类型,但在 result.additionalUserInfo.profile 中似乎没有明确的 first_name 或 last_name 嵌套定义。
type AdditionalUserInfo = {
isNewUser: boolean;
profile: Object | null;
providerId: string;
username?: string | null;
};
有什么办法可以解决这个问题并解决我面临的问题?我是否需要创建一个自定义类型来扩展 Firebase 的类型,如果是这种情况,最好的方法是什么?