Convex code generation where it doesn't give types when I run a mutation / query
I'm running into an issue with my Convex code generation where it doesn't give types when I run a mutation / query. Below would be an example of a query that I would send, but this would always be the type definition.
31 Replies
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!

@Clever Tagline super sorry just got back to my desk
No worries. Two things stick out to me:
1. Usually when importing
Doc I'm not used to seeing only the type imported. It normally imports like import { Doc } from .... However this might be irrelevant when considering what's next.
2. I'm also not used to seeing the handler return type spelled out. I've never done that myself as the function builder takes care of that automatically. And it's not the handler that you'd need to explicitly type because that's used internally, but that's beside the point. The way I would expect to see this coded is like this:
If you build it like that and hover over getUserSummary, you'll see that it automatically figures out the return type, so that anything calling it—like await ctx.runQuery—will know what type is returned.
Only recently did I see a way of explicitly indicating the return of the query, and it's done by adding a returns property to the object passed to internalQuery; e.g.
If you really want to go that route, the details are probably listed in the docs somewhere, but I haven't used that myself because I've never had the need. The built-in return type handling has always worked fine for me.
I gotta go, but I'll check back on this tomorrow. If you still can't get it working and anyone else wants to jump in and help in the meantime, feel free.Appreciate the write-up a lot, just remove the type from Doc and the spelled out return type.
I'm noticing even after i write those changes that the types are still the exact same. the reason why i hard typed it out (which still doesn't work lol) is because the engine wasn't able to figure it out.
this is super strange and possibly due to one small issue that i'm not aware of, maybe it's the v1 template i used?
GitHub
GitHub - get-convex/v1: An open-source starter kit based on Midday....
An open-source starter kit based on Midday. Ported to Convex. - get-convex/v1

maybe it's the v1 template i used?Perhaps? I've not used v1 before, so I'm not familiar with anything in it that might conflict with Convex. That's definitely weird that changing those items didn't improve anything. As for the hard typing thing, I believe the issue with what you had before was that you were typing the return from the handler. However, if I've learned anything about Convex, it's that there are layers hidden underneath, and my guess is that the part returning the data is likely not the anonymous function assigned to the handler in that definition. That function is just passed to
internalQuery, and something inside that is likely handling the actual return, so trying to force-type anything is moot because it's all under the covers (so to speak).
I'm gonna tag @erquhart for help with this, as I'm out of ideas.Did the v1 template already do this for you before any changes, with it's existing queries? I can take a look and try and repro if so
i'm not sure because i only noticed the type differences when i created like my 5th function
thank you for your help <3
You have convex dev running and seeing green check success when you make changes?
✔ 16:57:01 Convex functions ready! (5.35s)
Can you share your
convex/_generated/api.d.tsWhat file is this function in
getUserSummary
the function is defined in
packages/backend/convex/memory.ts
this is my tsconfig
I'm seeing the template does seem to have types
Did you make changes to tsconfig
nope, just cloned the v1 template again and i see the types 🤔
copied over the tsconfig for convex backend again
i noticed that the v1 has types for
getAuthSessionId
while mine has nothing (even when they're imported from the same source)

That's pretty odd
What am I looking at in those two screenshots, they look identical but one has types
yeah exactly
one is from teh template one is not, is there somewhere i should look into to check my types? ive been regenerating them using npx convex dev but is there anywhere else i shoudl look
there's definitely something wrong w/ the type system but i can't debug from where
Are these two files siblings?
this is from v1 repo the second one is from my repo
Any chance you have typechecking disabled in convex/schema.ts
oh no typechecking is enabled through cli
i see types through schema, but nothing else

If you write new functions in the template's files, they're typed correctly? Like this only happens in files you add?
correct, the template repository works with types — but the one that i forked doesn't so it might be because of some config on my repository that i shouldn't have touched
yeah I'd maybe get a fresh fork and port your added code over bit by bit until you find the culprit
😭
is there any where else i can check before doing that
i think i found the issue
it's the node modules...
but i'm seeing a completely different issue now, which is two exact same schemas erroring each other out