Francky
Francky•2d ago

Type error after upgrading from 1.18 to 1.26

Hi, I have a type that was working fine until I upgraded convex to the latest, any suggestion on what I should update my type to?
export type EventsArray = NonNullable<Awaited<ReturnType<typeof getByGroup>>>;
export type EventsArray = NonNullable<Awaited<ReturnType<typeof getByGroup>>>;
error:
Type error: Type 'RegisteredQuery<"public", { groupId: Id<"groups">; }, Promise<{ attendees: { _id: Id<"users">; username: string; avatarUrl: string | undefined; }[]; category: { _id: Id<"categories">; name: string; }; ... 9 more ...; endDate: string; }[]>>' does not satisfy the constraint '(...args: any) => any'.
Type 'RegisteredQuery<"public", { groupId: Id<"groups">; }, Promise<{ attendees: { _id: Id<"users">; username: string; avatarUrl: string | undefined; }[]; category: { _id: Id<"categories">; name: string; }; ... 9 more ...; endDate: string; }[]>>' provides no match for the signature '(...args: any): any'.
Type error: Type 'RegisteredQuery<"public", { groupId: Id<"groups">; }, Promise<{ attendees: { _id: Id<"users">; username: string; avatarUrl: string | undefined; }[]; category: { _id: Id<"categories">; name: string; }; ... 9 more ...; endDate: string; }[]>>' does not satisfy the constraint '(...args: any) => any'.
Type 'RegisteredQuery<"public", { groupId: Id<"groups">; }, Promise<{ attendees: { _id: Id<"users">; username: string; avatarUrl: string | undefined; }[]; category: { _id: Id<"categories">; name: string; }; ... 9 more ...; endDate: string; }[]>>' provides no match for the signature '(...args: any): any'.
getByGroup is defined like this
export const getByGroup = query({
args: { groupId: v.id("groups") },
handler: async (ctx, { groupId }) => {
const items = await ctx.db
.query("events")
.filter((q) => q.eq(q.field("group"), groupId))
.collect();

// for each item, get the user record for attendees and the category
return await Promise.all(
items.map(async (item) => {
const attendees = await Promise.all(
item.attendees.map(async (attendee) => {
const user = await ctx.db.get(attendee);
return {
_id: user!._id,
username: user!.username,
avatarUrl: user!.avatarUrl,
};
})
);
const category = item.category
? await ctx.db.get(item.category)
: undefined;
return {
...item,
attendees,
category: {
_id: category!._id,
name: category!.name,
},
};
})
);
},
});
export const getByGroup = query({
args: { groupId: v.id("groups") },
handler: async (ctx, { groupId }) => {
const items = await ctx.db
.query("events")
.filter((q) => q.eq(q.field("group"), groupId))
.collect();

// for each item, get the user record for attendees and the category
return await Promise.all(
items.map(async (item) => {
const attendees = await Promise.all(
item.attendees.map(async (attendee) => {
const user = await ctx.db.get(attendee);
return {
_id: user!._id,
username: user!.username,
avatarUrl: user!.avatarUrl,
};
})
);
const category = item.category
? await ctx.db.get(item.category)
: undefined;
return {
...item,
attendees,
category: {
_id: category!._id,
name: category!.name,
},
};
})
);
},
});
4 Replies
Convex Bot
Convex Bot•2d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Francky
FranckyOP•2d ago
There is no linting error in my file but my build fails because of that Got my answer, need to replace with export type EventsArray = typeof api.events.getByGroup._returnType;
Clever Tagline
Clever Tagline•2d ago
Glad that you found an answer. On a side note, I noticed that you're using .filter on the query to isolate documents for a specific group. Be aware that this will do a full table scan, which could become expensive over time. I recommend adding an index on the group field to make the query much more efficient.
Indexes | Convex Developer Hub
Speed up queries with database indexes
Francky
FranckyOP•15h ago
Good spotting! I need to refactor that. That was one of the very first query I implemented with convex a year ago, most of the queries now are using indexes but I didn't refactor the old ones. One more item on the todo list 😅 I'll also use the helpers for querying the relations

Did you find this page helpful?