I've run into a strange issue where if I import some Firebase types directly in my code I get "undefined is not an object" errors, but if I import them in an intermediary file and use them from there, then they work, so I have a firebaseTypes.ts file that looks like this:
import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore';
import { FirebaseStorageTypes } from '@react-native-firebase/storage';
export type NativeFirebaseError = ReactNativeFirebase.NativeFirebaseError;
export type TaskSnapshot = FirebaseStorageTypes.TaskSnapshot;
export type Reference = FirebaseStorageTypes.Reference;
export type DocumentChange = FirebaseFirestoreTypes.DocumentChange;
export type SnapshotListenOptions = FirebaseFirestoreTypes.SnapshotListenOptions;
Now I'm trying to use FieldPath.documentId() in a query and hit an error trying to import FieldPath, so I add it to my firebaseTypes.ts
document too:
export type FieldPath = FirebaseFirestoreTypes.FieldPath;
And in my dao.ts
file I have a query that looks like this:
const fooIds: string[] = allFoo.map(f => f.fooId);
const updatedFoo: Foo[] | undefined = await db.collection<FirestoreFoo>(fooCollectionName)
.where('userId', '==', uid)
.where(FieldPath.documentId(), 'in', fooIds)
.then(async (querySnapshot: QuerySnapshot) => {
log.info('updateFooPhotos got a list of size: ', querySnapshot.size);
return await processFooQuerySnapshot(querySnapshot, uid);
}, (e) => {
handleError(e, log);
return undefined;
});
This query runs successfully and gets me the results I want, but IntelliJ underlines FieldPath
in red and gives the error "TS2693: 'FieldPath' only refers to a type, but is being used as a value here."
I've tried modifying my import in firebaseTypes.ts but can't seem to make it work in a way that removes this error.
Is it safe to ignore it since my function is working? Or is there something else I should be doing to mitigate this?
I changed my firebaseTypes.ts
FieldPath imports and exports to look like this and it fixed the issue:
import firestore from '@react-native-firebase/firestore';
const FieldPath = firestore.FieldPath;
export { FieldPath }