WinstonW
Convex Community4w ago
1 reply
Winston

(q) callback inside a query causes types to be inferred as any

🪲Bug Report
I have the following code:

import { api } from "../_generated/api";
import { query } from "../_generated/server";
import { UserIdentityWithOrganization } from "./schema";

export const get = query({
  args: {},
  handler: async (ctx) => {
    const user =
      (await ctx.auth.getUserIdentity()) as UserIdentityWithOrganization;
    if (!user) {
      throw new Error("Not authenticated");
    }

    const organization = await ctx.runQuery(
      api.auth.organizations.getOrganizationNameByWosId,
      {
        wosId: user.organizationId,
      }
    );
    if (!organization) {
      throw new Error("Not authenticated");
    }

    return ctx.db
      .query("customerSettings")
      .filter((q) => q.eq(q.field("organizationId"), organization.id)) // this 
      .first();
  },
});


The (q) callback to filter (both inside filter and withIndex) breaks all type inference in this function, causing things to be typed as
any
. Has anybody encountered this before?

ts      .withIndex("byOrganizationId", (q) =>
        q.eq("organizationId", organization.id)
      )
image.png
image.png
image.png
image.png
Was this page helpful?