Skip to content

no $option in FilterOperators for $regex?Β #405

@xb1g

Description

@xb1g

The code works but type show as error at $options

Argument of type '{ $or: ({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]; } | {}' is not assignable to parameter of type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }> | undefined'.
  Type '{ $or: ({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
    Types of property '$or' are incompatible.
      Type '({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>[]'.
        Type '{ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
          Type '{ username: { $regex: string; $options: string; }; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
            Types of property 'username' are incompatible.
              Type '{ $regex: string; $options: string; }' is not assignable to type 'string | FilterOperators<string> | undefined'.
                Object literal may only specify known properties, and '$options' does not exist in type 'FilterOperators<string>'.deno-ts(2345)

  const users = await Users.find(
    search
      ? {
          $or: [
            { username: { $regex: search, $options: "i" } }, // 'i' for case-insensitive
            { name: { $regex: search, $options: "i" } },
          ],
        }
      : {},
    {
      projection: { password: 0 },
    }
  ).toArray();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions