Tom RedmanT
Convex Community12mo ago
24 replies
Tom Redman

Type error when NOT directly calling function (new to Convex 1.18.2)

I see in the update notes, it's not a good practice to call a function directly from another function.

However, when rectifying this (e.g. using ctx.runQuery(myApiQuery) vs myApiQuery() I'm getting the stubborn "Function implicitly has return type 'any' because..." error.

Any idea why this is now upsetting the type system?

I feel like I'm missing something obvious!

export const getForCurrentUser = query({
  args: {},
  handler: async (ctx) => {
    const { user, team } = await ctx.runQuery(
      internal.authentication.user.getCurrentUserOrThrow
    );
    return await ctx.db
      .query("mailchimpLists")
      .withIndex("by_team", (q) => q.eq("teamId", team._id))
      .collect();
  },
});


And then I have this query:
export const getCurrentUserOrThrow = internalQuery({
  args: {},
  handler: async (ctx): Promise<{ user: Doc<"users">; team: Doc<"teams"> }> => {
    const userId = await getAuthUserId(ctx);
    if (!userId) {
      throw new Error("Not signed in");
    }

    const user = await ctx.db.get(userId);

    if (!user) {
      throw new Error("User not found");
    }

    const teamId = user.teamId;

    if (!teamId) {
      throw new Error("User is not in a team");
    }

    const team = await ctx.db.get(teamId);

    if (!team) {
      throw new Error("Team not found");
    }

    return { user, team };
  },
});
Was this page helpful?