I have been unable to find any reasoning for the current state of this package's TypeScript definitions, but it would be useful for us to have more, if not all, Type definitions exported. For example, currently to correctly type the onAuthStateChanged I would need to be able to import the OrNull type as well as the User type, neither of which are currently exported from index.d.ts .
import { OrNull, User } from "react-native-firebase";
// Listen for FireBase auth events
authRef.onAuthStateChanged((user: OrNull<User>) => {
// Example code
const email: string = user && user.email
? user.email
: "";
// ... do something with user email
});
Instead of the above, I must either create my own stubbed type definitions file or use the loose and useless any type. Is it possible this was just an oversight? Can we export or these types or is there a reasoning behind leaving them private?
I wasn't sure whether to file this as a feature or bug, if it needs moved just let me know.
Thanks!
I have good luck with this?
import firebase { RNFirebase } from 'react-native-firebase';
interface PhoneVerifyState {
user: RNFirebase.User | null;
}
class PhoneVerifyPanel extends RX.Component<NavigationScreenProps, PhoneVerifyState> {
constructor(props: NavigationScreenProps) {
super(props);
this.state = {
user: null,
};
}
private async addAuthListener() {
this.authUnsubscriber = firebase.auth().onAuthStateChanged(async user => {
this.setState({
user,
});
});
}
Yep you're right that works. I had actually tried that before with no luck according to my IDE, but it must have just not synced yet. Thanks @mikehardy !
Glad to hear I'm not crazy myself actually, coding alone over here and new to Typescript :-). Nice to compare notes. Cheers
These are much better in v6, 100% typescript def coverage + exports - but not released yet - just a heads up that we're aware they could be better and are doing something about them 馃檭
Most helpful comment
These are much better in v6, 100% typescript def coverage + exports - but not released yet - just a heads up that we're aware they could be better and are doing something about them 馃檭