ThoorAdam
ThoorAdam3mo ago

Paginated query type error

Getting the following error from my paginated query
Argument of type 'FunctionReference<"query", "public", { checklistId: Id<"checklists">; paginationOpts: { id?: number | undefined; endCursor?: string | null | undefined; maximumRowsRead?: number | undefined; maximumBytesRead?: number | undefined; numItems: number; cursor: string | null; }; }, PaginationResult<...> | null, string | un...' is not assignable to parameter of type 'PaginatedQueryReference'.
Types of property '_returnType' are incompatible.
Type 'PaginationResult<{ _id: Id<"checklistItems">; _creationTime: number; checklistId: Id<"checklists">; text: string; completed: boolean; }> | null' is not assignable to type 'PaginationResult<any>'.
Type 'null' is not assignable to type 'PaginationResult<any>'.
Argument of type 'FunctionReference<"query", "public", { checklistId: Id<"checklists">; paginationOpts: { id?: number | undefined; endCursor?: string | null | undefined; maximumRowsRead?: number | undefined; maximumBytesRead?: number | undefined; numItems: number; cursor: string | null; }; }, PaginationResult<...> | null, string | un...' is not assignable to parameter of type 'PaginatedQueryReference'.
Types of property '_returnType' are incompatible.
Type 'PaginationResult<{ _id: Id<"checklistItems">; _creationTime: number; checklistId: Id<"checklists">; text: string; completed: boolean; }> | null' is not assignable to type 'PaginationResult<any>'.
Type 'null' is not assignable to type 'PaginationResult<any>'.
const completedChecklistItems = usePaginatedQuery(
api.checklists.getCompletedChecklistItemsByChecklistId,
activeTab === 1 || hasActivatedCompletedTab ? { checklistId: checklistId as Id<'checklists'> } : 'skip',
{
initialNumItems: 25,
},
);
const completedChecklistItems = usePaginatedQuery(
api.checklists.getCompletedChecklistItemsByChecklistId,
activeTab === 1 || hasActivatedCompletedTab ? { checklistId: checklistId as Id<'checklists'> } : 'skip',
{
initialNumItems: 25,
},
);
const items = await ctx.db
.query('checklistItems')
.withIndex('checklistId', (q) => q.eq('checklistId', args.checklistId))
.filter((q) => q.eq(q.field('completed'), true))
.paginate(args.paginationOpts);

return items;
const items = await ctx.db
.query('checklistItems')
.withIndex('checklistId', (q) => q.eq('checklistId', args.checklistId))
.filter((q) => q.eq(q.field('completed'), true))
.paginate(args.paginationOpts);

return items;
Everything seems to be working correctly though even with the error.
6 Replies
Convex Bot
Convex Bot3mo 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!
ampp
ampp3mo ago
I think its because your filter could cause it to return null. which blows up paginate some people filter null results first i can think of 5 ways to fix it.
ThoorAdam
ThoorAdamOP3mo ago
I'm not conviced that's it. Even if I remove the filter and withIndex completely I get the same type error.
ampp
ampp3mo ago
in that case it could still possibly return null if the table is empty it shouldnt error if you are only using withIndex.. i never do full table scans
djbalin
djbalin3mo ago
Could you paste the full query implementation @ThoorAdam ?
ThoorAdam
ThoorAdamOP3mo ago
It's solved now, it didn't have to do with my query at all. One of my "guard" functions returned null instead of throwing an error when execution shouldn't continue.

Did you find this page helpful?