Running into this same typescript error
I know i've asked for help on this before, but I can't figure out how to resolve this issue... for some reason because the runQuery returns a Doc<"users">, this action just won't compile

10 Replies
this issue is pretty painful tbh
this is my current fix
adding :any and then manually casting fields from that user: any
Can you try and just return user directly like.
return User;
What is likely happening here is that you end up in an infinite loop. And since ur only returning user In this case, I would just return it directly.
I’ve had a similar issue before, that might be related to this too. So you can read this thread, it’s valuable info for similar issues in the future: https://discord.com/channels/1019350475847499849/1199697643421573170This is a reasonable fix, if you can share a type between these files that you explicitly annotate the
getUserById
return type with and use here instead of any that would help.
hmm looking closer I see this is about customAction, customCtx etc. It might help to type import getUserById
into this file directly and annotate const user: ReturnType<typeof getUserById>
directly. It might help to explicitly annotate the return type of getUserById in the implementation.
We should write up a problem solving flowchart here, agree @Web Dev Cody that this is painful. A longer term fix is adding output validators to functions which we don't have official syntax for yet but is a direction we'll go down for better code generation. (OpenAPI spec generation, etc.)
yeah same issue with the user: annotation
the fact that the custom action callback returns the user object seems to just break it
This cannot work, this cycle is still there:

@Web Dev Cody you want:
or similar (depends on what
getUserById
actually returns).I think I’ve also tried that
I’ll try again in a bit
Hey @Web Dev Cody , how did you get on with this problem? I'm using Michael's suggestion as a fix but just wondering if you've found a better way
This is the correct workaround, and we have it now documented in the docs:
https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment