In the current logic, there is a function that handles specific data record processing stored in firestore:
private listenUserData (): void {
this.unListenUserData = FirebaseDb
.collection(`users`).doc(this.user.id)
.collection(`userData`)
.onSnapshot({ includeMetadataChanges: true }, (querySnapshot) => {
const changes = getUserDataSnapshotChanges(querySnapshot)
const { data, changeType } = changes
data.config && this.handleConfigChanges(data.config, changeType)
data.personalData && this.handlePersonalDataChanges(data.personalData)
})
}
This function uses a utility that processes the querySnapshot and returns an object:
export function getUserDataSnapshotChanges (querySnapshot: any): UserDataSnapshotChangesType {
const changes: UserDataSnapshotChangesType = {
data: {},
changeType: ``,
isEmpty: querySnapshot.empty
}
querySnapshot.docChanges().forEach((docChange: any) => {
const { doc } = docChange
changes.data[doc.id] = doc.data()
changes.changeType = docChange.type
})
return changes
}
Currently, the QuerySnapshot and docChange use the any type. Attempts to import DocumentChange
from 'firebase' have not been successful.
I have investigated the index.d.ts of firebase and found that the following type belongs to the namespace firebase.firestore
:
https://i.sstatic.net/QiOny.jpg
If anyone has ideas regarding this situation, I would greatly appreciate it:
1. Does this mean there is no way to import that type if it's part of a non-exported namespace?
2. If not, what could be a possible approach to access firestore for type-safe code?