Type inference is not working when findFirst is extracted

Hey typescript wizards, could anyone spot what I'm doing wrong here?

type OrgTableQueryParams = Parameters<
  typeof db.query.organizationTable.findFirst
>[0] & {};
export const getOrganizationById = cache(
  (id: string, queryParams?: OrgTableQueryParams) => {
    return db.query.organizationTable.findFirst({
      where: (table, { eq }) => eq(table.id, id),
      ...queryParams,
    });
  }
);


But when I use it like this the types are not getting inferred from the with params:

const organization = await getOrganizationById(user.organizationId, {
      with: {
        slackWorkspace: {
          with: {
            channels: true,
          },
        },
      },
    });


Thanks 🙏
Was this page helpful?