Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰] 馃敟Filter.and and Filter.or should be able to accept Filter.and or Filter.or as their argument #7850

Open
2 of 10 tasks
thisisgit opened this issue Jun 19, 2024 · 0 comments
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report

Comments

@thisisgit
Copy link

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:
釀夅叧釀忈叧釀呩叺釂剦釁a喓 2024-06-19 釀嬦叐釀掅叜 4 09 52

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:

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;
/**
* 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;
}

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:

  • 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.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for 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
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • 20.0.0
  • Firebase module(s) you're using that has the issue:
    • Firestore
  • Are you using TypeScript?
    • Y & 5.3.3


@thisisgit thisisgit added Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report
Projects
None yet
Development

No branches or pull requests

1 participant