beerman
beerman3w ago

Not getting indexRange callback type

Hey all, I'm having an issue with one of my queries where the type of q inside withIndex is not being inferred. Did I miss something?
export const getSpins = query({
args: {
limit: v.optional(v.number()),
before: v.optional(v.number()),
after: v.optional(v.number()),
},
handler: async (ctx, args) => {
// base query using timestamp index
const query = await ctx.db
.query("spins")
.withIndex("by_timestamp", (q) => {
// Build query based on provided arguments
if (args.after && args.before) {
// Range query
q = q.gte("timestamp", args.after).lt("timestamp", args.before);
} else if (args.after) {
q = q.gte("timestamp", args.after);
} else if (args.before) {
q = q.lt("timestamp", args.before);
}
})
.order("desc")
.take(args.limit || 10000);

return query;
},
});
export const getSpins = query({
args: {
limit: v.optional(v.number()),
before: v.optional(v.number()),
after: v.optional(v.number()),
},
handler: async (ctx, args) => {
// base query using timestamp index
const query = await ctx.db
.query("spins")
.withIndex("by_timestamp", (q) => {
// Build query based on provided arguments
if (args.after && args.before) {
// Range query
q = q.gte("timestamp", args.after).lt("timestamp", args.before);
} else if (args.after) {
q = q.gte("timestamp", args.after);
} else if (args.before) {
q = q.lt("timestamp", args.before);
}
})
.order("desc")
.take(args.limit || 10000);

return query;
},
});
4 Replies
Convex Bot
Convex Bot3w 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!
beerman
beermanOP3w ago
No description
lee
lee3w ago
Instead of q = q.whatever() should be return q.whatever() ah i see your #ask-ai thread found the solution. Who's a good kapa 🐶
beerman
beermanOP3w ago
Indeed. Good job Kappa

Did you find this page helpful?