RJR
Convex Community2y ago
7 replies
RJ

Nested optional search field type error

Given a schema that looks like this:

    documents: defineTable({
      fieldOne: v.string(),
      fieldTwo: v.optional(v.object({
        subFieldOne: v.string(),
      })),
    }).searchIndex("search_field_two", {
      searchField: "fieldOne",
      filterFields: ["fieldTwo.subFieldOne"],
    }),


The following query produces a type error:

    const data = await ctx.db
      .query("documents")
      .withSearchIndex("search_field_two", (q) =>
        q
          .search("fieldOne", "string")
          .eq(
            "fieldTwo.subFieldOne",
            "string"
          // ^ Argument of type '"string"' is not assignable to parameter of type 'undefined'.
          )
      )
      .collect();


Repro:
- GH repo: https://github.com/rjdellecese/nested-optional-search-filter-field-test
- Offending line: https://github.com/rjdellecese/nested-optional-search-filter-field-test/blob/04dd3545aa0e83ed6deac84b186b6e64e43d4c59/convex/myFunctions.ts#L83
Was this page helpful?