Currently facing an issue that seems straightforward but is proving difficult to resolve. Despite thorough documentation review and a lack of similar inquiries, I am encountering difficulties.
My project involves building an app using React Native, where documents are generated and transmitted to a Firebase function operated by an Express server connecting to Firestore through the Admin SDK for node@10. The primary obstacle lies in efficiently representing dates to avoid continuous conversions between various date fields within my documents and subdocuments. Initializing the react native firebase connection with
import * as firebase from firebase
, and firebase.initializeApp(...config)
. The Timestamp object provided by this library is listed as firebase.firestore.Timestamp
. Conversely, on the server side, initialization occurs using import * as admin from 'firebase-admin'
followed by admin.initializeApp(credential, ...config)
. In this context, the Timestamp is identified as FirebaseFirestore.Timestamp sourced from the google-api library rather than firestore. Consequently, when attempting to parcel an object of this type from the server to the client or vice versa, typescript compilation fails due to incompatible types.
My latest endeavor involved utilizing the Date
object which unfortunately gets automatically converted into a FirebaseFirestore.Timestamp
object upon submission to Firestore. This process leads back to my initial issue of evading manual conversion for every object before performing a typecheck at both ends of the REST API.
Any advice on resolving this dilemma? While lacking a replicable example here, I believe it's primarily a type discrepancy rather than a programming flaw.
Your assistance would be greatly appreciated!
(Additionally, the inability to utilize @firebase/testing
's initializeTestApp()
stems from the contradictory nature of FirebaseFirestore.Firestore and firebase.firestore.Firestore, creating uncertainty if they belong to the same classification of errors as the current one.)