-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Labels
Needs Attentionplatform: allplugin: firestoreFirebase Cloud FirestoreFirebase Cloud Firestoretype: bugNew bug reportNew bug report
Description
Issue
We noticed that our TypeScript setup doesn't work anymore with the latest 22.3.0
. This is most likely caused by #8378.
One cause could be that the following type points to Query<AppModelType, DbModelType>
:
react-native-firebase/packages/firestore/lib/modular/query.d.ts
Lines 103 to 107 in 7eaaf18
export declare function query<AppModelType, DbModelType extends DocumentData>( | |
query: Query<AppModelType, DbModelType>, | |
compositeFilter: QueryCompositeFilterConstraint, | |
...queryConstraints: QueryNonFilterConstraint[] | |
): Query<AppModelType, DbModelType>; |
But that type (and similar ones in this file) was not updated and doesn't support the second parameter:
export interface Query<T extends DocumentData = DocumentData> { |
For reference this is how this is typed in firebase-js-sdk
:
Using this type:
Reproducible example with type errors
rnfirebase-example.ts
:
- ✅: works as expected
- 🤔: The custom type disappeared for some reason.
- 🚨: why is this suddenly
any
?
import {
collection,
doc,
FirebaseFirestoreTypes,
getDoc,
getDocs,
getFirestore,
limit,
query,
} from '@react-native-firebase/firestore'
type UserType = { id: string }
const firestore = getFirestore()
/// OLD API ///
{
// GET SINGLE DOCUMENT //
// 22.2.1 `FirebaseFirestoreTypes.DocumentReference<UserType>` ✅
// 22.3.0 `FirebaseFirestoreTypes.DocumentReference<UserType>` ✅
// Expected: `FirebaseFirestoreTypes.DocumentReference<UserType>`
const userReferenceWithT = doc(
firestore,
'users/123',
// this cast worked in 22.2.1, should actually be `doc<UserType>`
) as FirebaseFirestoreTypes.DocumentReference<UserType>
// 22.2.1 `FirebaseFirestoreTypes.DocumentSnapshot<UserType>` ✅
// 22.3.0 `FirebaseFirestoreTypes.DocumentSnapshot<UserType>` ✅
// Expected: `FirebaseFirestoreTypes.DocumentSnapshot<UserType>`
const userSnapshotWithT = await getDoc(userReferenceWithT)
// 22.2.1 `UserType | undefined` ✅
// 22.3.0 `UserType | undefined` ✅
// Expected: `UserType | undefined`
const _userWithT = userSnapshotWithT.data()
// GET MULTIPLE DOCUMENTS FROM COLLECTION //
// 22.2.1: `FirebaseFirestoreTypes.Query<UserType>` ✅
// 22.3.0: `FirebaseFirestoreTypes.Query<UserType>` ✅
// Expected: `FirebaseFirestoreTypes.Query<UserType>`
const usersQueryReferenceWithT = query(
// this cast worked in 22.2.1, should actually be `query<UserType>`
collection(firestore, 'users') as FirebaseFirestoreTypes.CollectionReference<UserType>,
limit(10),
)
// 22.2.1 `FirebaseFirestoreTypes.QuerySnapshot<UserType>` ✅
// 22.3.0 `any` 🚨
// Expected: `FirebaseFirestoreTypes.QuerySnapshot<UserType, UserType>`
const usersSnapshotWithT = await getDocs(usersQueryReferenceWithT)
// 22.2.1: `UserType[]` ✅
// 22.3.0 `any` 🚨
// Expected: `UserType[]`
const _usersWithT = usersSnapshotWithT.docs.map((d) => d.data())
}
/// UPDATED API ///
{
// GET SINGLE DOCUMENT //
// 22.2.1: ... didn't exist ...
// 22.3.0 `any` 🚨
// Expected: `FirebaseFirestoreTypes.DocumentReference<UserType, UserType>`
const userReferenceWithT = doc<UserType, UserType>(firestore, 'users/123')
// 22.2.1: ... didn't exist ...
// 22.3.0 `FirebaseFirestoreTypes.DocumentSnapshot<unknown>` 🤔
// Expected: `FirebaseFirestoreTypes.DocumentSnapshot<UserType, UserType>`
const userSnapshotWithT = await getDoc(userReferenceWithT)
// 22.2.1: ... didn't exist ...
// 22.3.0 `unknown` 🤔
// Expected: `UserType | undefined`
const _userWithT = userSnapshotWithT.data()
// GET MULTIPLE DOCUMENTS FROM COLLECTION //
// 22.2.1: ... didn't exist ...
// 22.3.0: `any` 🚨
// Expected: `FirebaseFirestoreTypes.Query<UserType, UserType>`
const usersQueryReferenceWithT = query<UserType, UserType>(
collection(firestore, 'users'),
limit(10), // This isn't valid for some reason 🚨
)
// 22.2.1: ... didn't exist ...
// 22.3.0 `any` 🚨
// Expected: `FirebaseFirestoreTypes.QuerySnapshot<UserType, UserType>`
const usersSnapshotWithT = await getDocs(usersQueryReferenceWithT)
// 22.2.1: ... didn't exist ...
// 22.3.0 `any` 🚨
// Expected: `UserType[]`
const _usersWithT = usersSnapshotWithT.docs.map((d) => d.data())
}
- 👉 Check out
React Native Firebase
andInvertase
on Twitter for updates on the library.
TomasBruno1 and Polarisation
Metadata
Metadata
Assignees
Labels
Needs Attentionplatform: allplugin: firestoreFirebase Cloud FirestoreFirebase Cloud Firestoretype: bugNew bug reportNew bug report