Reactjs 如何在react中为firebase对象编写类型定义?
我正在尝试将firebase与react native(expo)集成。我遵循找到的firebase文档。文档非常直截了当,并按预期工作,但由于文档是JS格式的,并且我正在使用typescript进行编码,因此我的linter上出现了不少错误 关于下面的代码,我想谈几点Reactjs 如何在react中为firebase对象编写类型定义?,reactjs,typescript,firebase,react-native,Reactjs,Typescript,Firebase,React Native,我正在尝试将firebase与react native(expo)集成。我遵循找到的firebase文档。文档非常直截了当,并按预期工作,但由于文档是JS格式的,并且我正在使用typescript进行编码,因此我的linter上出现了不少错误 关于下面的代码,我想谈几点 我已经成功地定义了AuthenticatedUser,因为当我在signInWithGooglAsync中调用方法onSignIn(result)时,参数的类型会改变 在onSignIn函数中,我从firebase接收到一个值。
interface SuccessfullyAuthenticatedUser {
...
type: "success";
getBasicProfile?: any;
}
const signInWithGoogleAsync = async () => {
try {
const result = await Google.logInAsync({...});
if (result.type === "success") {
onSignIn(result);
...
}
...
} catch (e) {
...
}
};
const onSignIn = (googleUser: SuccessfullyAuthenticatedUser) => {
....
....
firebase.auth().signInWithCredential(credential).then((value) => {
const profile: any = value.additionalUserInfo?.profile;
firebase.database().ref(...).set({
...
first_name: profile.given_name,
});
})
...
});
};
const isUserEqual = (
googleUser: SuccessfullyAuthenticatedUser,
firebaseUser: firebase.User | null,
) => {
if (firebaseUser) {
if (providerData[i]!.uid === googleUser.getBasicProfile().getId()){
...
}
return false;
};