I'm trying to solve an issue that seems like it should be an easy fix, but I can't find anything in the documentation about it, and there doesn't seem to be any questions regarding it.
I'm building an app with React Native, where we create various documents relating to the app, and send these to a Firebase function running an express server that connects to Firestore with the Admin SDK for node@10. My issue is trying to find some sensible way to represent dates without having to convert everything back and forth every time, since there are quite a few date fields in my documents/subdocuments. I initialize the react native firebase connection with import * as firebase from firebase
and firebase.initializeApp(...config)
here. The Timestamp object for this library has type firebase.firestore.Timestamp
. Meanwhile, on my server, I initialize with import * as admin from 'firebase-admin'
and admin.initializeApp(credential, ...config)
. Here, the type of Timestamp is FirebaseFirestore.Timestamp, and comes from the google-api library, instead of the firestore library. When I then send an object with this type from the server to the client, or the other way around, typescript compilation fails because the two types are incompatible.
My most recent attempt at doing this was to use the Date
object, but when I send this to Firestore, it automatically converts it to a FirebaseFirestore.Timestamp
object, which leads me back to my original problem of not wanting to manually convert every object before I typecheck it (on each end of the REST API).
Any tips or hints on how I can fix this? I know I don't have a reproducible example here, but I don't really see the need for it, since it's more of a type issue than actual programming.
Thanks for any help!
(I also can't use @firebase/testing
's initializeTestApp()
because of this, because FirebaseFirestore.Firestore and firebase.firestore.Firestore are two different types, which I don't know if in the same category of error as this one.)