Reactjs 从firebase使用FetchSignInMethodForEmail方法时获取typescript错误
我正在尝试在react typescript应用程序中实现firebase身份验证。我也在使用FetchSignInMethodForEmail方法,但我无法解决错误 代码是:Reactjs 从firebase使用FetchSignInMethodForEmail方法时获取typescript错误,reactjs,typescript,firebase,firebase-authentication,Reactjs,Typescript,Firebase,Firebase Authentication,我正在尝试在react typescript应用程序中实现firebase身份验证。我也在使用FetchSignInMethodForEmail方法,但我无法解决错误 代码是: if(error.code === 'auth/account-exists-with-different-credential') { var pendingCred = error.credential; var existingEmail = error.email; fire.auth.fetchSignInM
if(error.code === 'auth/account-exists-with-different-credential') {
var pendingCred = error.credential;
var existingEmail = error.email;
fire.auth.fetchSignInMethodsForEmail(existingEmail).then(methods => {
if(methods[0] === 'password') {
var password = window.prompt('Enter Password for Existing Email: ' + existingEmail) as string;
fire.auth.signInWithEmailAndPassword(existingEmail, password).then(fbUser => {
return fbUser.user.linkWithCredential(pendingCred);
}).then(fbUser => {
this.props.loginUserSuccess(fbUser);
});
return;
}
})
}
执行then方法时,第5行return语句中出现错误:
类型为“(providers:string[])=>Promise | undefined”的参数不能分配给类型为“(value:string[])=>UserCredential | PromiseLike”的参数。
类型“Promise | undefined”不可分配给类型“UserCredential | PromiseLike”。
类型“未定义”不可分配给类型“UserCredential | PromiseLike”
包含上述代码的函数:
loginMicrosoft = () => {
this.props.loginUser();
var microsoftProvider = new firebase.auth.OAuthProvider("microsoft.com");
microsoftProvider.setCustomParameters({
prompt: 'select_account'
});
fire.auth
.signInWithPopup(microsoftProvider)
.then( msUser => {
this.props.loginUserSuccess(msUser);
})
.catch(error => {
if(error.code === 'auth/account-exists-with-different-credential') {
var pendingCred = error.credential;
var existingEmail = error.email;
fire.auth.fetchSignInMethodsForEmail(existingEmail).then(methods => {
if(methods[0] === 'password') {
var password = window.prompt('Enter Password for Existing Email: ' + existingEmail) as string;
fire.auth.signInWithEmailAndPassword(existingEmail, password).then(fbUser => {
return fbUser.user.linkWithCredential(pendingCred);
}).then(fbUser => {
this.props.loginUserSuccess(fbUser);
});
return;
}
})
}
});
}
我把错误解决了。该函数可能返回未定义的,但不应该是这种情况。我添加了一些条件来解决错误 解决方案: 我将用户存储在变量中,并将其值存储为firebase.user,从而解决了问题 例如:
const fbUser = user.user as firebase.User
你能把问题编辑得更具体一点吗?这个错误指的是哪一行代码?我们应该能够观察到你所观察到的。是的。我已经编辑了这个问题。它在执行.then方法时会显示在return语句上。我认为您可能需要显示更多代码。这是在另一个函数中吗?我们应该能够复制代码并自己看到错误。见: