Meexa
Meexa2w ago

Returning response from runQuery in a query breaks typescript

As seen in the included images: in the first image I return data from the runQuery and now the entire function and everything in it resolves to any. When I remove the return (or change it to something like return 1) the types work again. I've had this before with actions as well. I think the issue is with runQuery because when I return data I get from ctx.db it works fine. I guess this is a bug? I can't find anything in the docs that state I shouldn't return data from runQuery. Or is there something else that I might be doing wrong?
No description
No description
2 Replies
Meexa
MeexaOP2w ago
Extracted the logic from the queries to functions and using them in both queries now. This resolved my issue.
No description
No description
No description
sshader
sshader2w ago
I'd guess you were running into something like https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference, and generally adding some more explicit type annotations helps. But also splitting logic into helper functions is the better pattern vs. ctx.runQuery (https://docs.convex.dev/understanding/best-practices/#use-ctxrunquery-and-ctxrunmutation-sparingly-in-queries-and-mutations)
Best Practices | Convex Developer Hub
This is a list of best practices and common anti-patterns around using Convex.
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment

Did you find this page helpful?