[🐛] 🔥`Filter.and` and `Filter.or` should be able to accept `Filter.and` or `Filter.or` as their argument
Issue
According to the document Filter.or and Filter.and should be able to accept themselves as arg:
const snapshot = await firestore()
.collection('Users')
.where(
firestore.Filter.or(
firestore.Filter.and(firestore.Filter('user', '==', 'Tim'), firestore.Filter('email', '==', '[email protected]')),
firestore.Filter.and(firestore.Filter('user', '==', 'Dave'), firestore.Filter('email', '==', '[email protected]')),
),
)
.get();
(Note that I've updated Filter to firestore.Filter due to this issue)
However this throws type error:
This is happening because type of Filter.or and Filter.and only accepts type of QueryFilterConstraint while what they're returning is type of QueryCompositeFilterConstraint:
https://github.com/invertase/react-native-firebase/blob/ca07cadd592487102b035a24b55f593f065ef4a5/packages/firestore/lib/index.d.ts#L71-L87
So to address this issue, their type needs to be adjusted to accept either QueryFilterConstraint or QueryCompositeFilterConstraint:
export interface FilterFunction {
/**
* The Filter function used to generate an instance of Filter.
* e.g. Filter('name', '==', 'Ada')
*/
(fieldPath: keyof T | FieldPath, operator: WhereFilterOp, value: any): QueryFilterConstraint;
/**
* The Filter.or() static function used to generate a logical OR query using multiple Filter instances.
* e.g. Filter.or(Filter('name', '==', 'Ada'), Filter('name', '==', 'Bob'))
*/
or(...queries: (QueryFilterConstraint | QueryCompositeFilterConstraint)[]): QueryCompositeFilterConstraint;
/**
* The Filter.and() static function used to generate a logical AND query using multiple Filter instances.
* e.g. Filter.and(Filter('name', '==', 'Ada'), Filter('name', '==', 'Bob'))
*/
and(...queries: (QueryFilterConstraint | QueryCompositeFilterConstraint)[]): QueryCompositeFilterConstraint;
}
This works as I tested by updating the file in node_modules.
But will the change introduce any other issues that I'm not aware of?
Project Files
Managed expo
Javascript
Click To Expand
package.json:
"@react-native-firebase/analytics": "20.0.0",
"@react-native-firebase/app": "20.0.0",
"@react-native-firebase/app-check": "20.0.0",
"@react-native-firebase/auth": "20.0.0",
"@react-native-firebase/crashlytics": "20.0.0",
"@react-native-firebase/firestore": "20.0.0",
"@react-native-firebase/functions": "20.0.0",
firebase.json for react-native-firebase v6:
# N/A
iOS
Click To Expand
ios/Podfile:
- [x] I'm not using Pods
- [ ] I'm using Pods and my Podfile looks like:
# N/A
AppDelegate.m:
// N/A
Android
Click To Expand
Have you converted to AndroidX?
- [ ] my application is an AndroidX application?
- [ ] I am using
android/gradle.settingsjetifier=truefor Android compatibility? - [ ] I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// N/A
android/app/build.gradle:
// N/A
android/settings.gradle:
// N/A
MainApplication.java:
// N/A
AndroidManifest.xml:
<!-- N/A -->
Environment
Click To Expand
react-native info output:
OUTPUT GOES HERE
-
Platform that you're experiencing the issue on:
- [ ] iOS
- [ ] Android
- [x] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
-
react-native-firebaseversion you're using that has this issue:-
20.0.0
-
-
Firebasemodule(s) you're using that has the issue:-
Firestore
-
-
Are you using
TypeScript?-
Y&5.3.3
-
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.