Drips
Drips2mo ago

Type instantiation is excessively deep and possibly infinite.

I feel like a complete noob - I’m sorry. I’m in a migration from supabase, which I used with zod, to convex. And I now often times run into this TS error. Which right now I don’t know to fix because I don’t understand what’s the actual problem. Claude is simply removing all types says it’s any and calls it a day which of cause is bad. Also interesting sometimes the error is there but then disappears by itself. So can I fine tune my linting for this?
12 Replies
Convex Bot
Convex Bot2mo 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!
Snazzie
Snazzie2mo ago
yep my entire convex folder just lit up with errors crazy this is horrible dev experience even if i explictely type the response whats weird is that it initially is able to detect the types and it then crashes out
Snazzie
Snazzie5w ago
like this for example
No description
Snazzie
Snazzie5w ago
the bottom variable is able to resolve its type. but the same func call at top cant exact same func call
erquhart
erquhart5w ago
You can't return requisitionInDb from a convex function because it's the return type of another convex function, which creates the infinite type loop. More here: https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference
Actions | Convex Developer Hub
Call third-party services and external APIs from Convex
erquhart
erquhart5w ago
You need to type the enclosing function in a way that does not rely on type inference through the ctx.run* call. Which means something like const requisitionInDb: Doc<'requisitions'> = await ctx.runQuery(...) won't work, as Doc and friends still rely on Convex generated types. I usually try to slim down the return value if possible to simplify these cases. So, for example, if you don't actually need the whole requisitionInDb object, but maybe just a few props, just type those props explicitly inline and return those. But if you need the whole object the solution looks similar either way.
// Return partial
const {
field: string,
otherField: number
} = (await ctx.runQuery(internal.some.query, { ...args })) || {}
return { field, otherField }

// Return full doc
const requisitionInDb: {
every: string,
field: number,
typed: string,
here: number
} = (await ctx.runQuery(internal.some.query, { ...args })) || {}
return requisitionInDb
// Return partial
const {
field: string,
otherField: number
} = (await ctx.runQuery(internal.some.query, { ...args })) || {}
return { field, otherField }

// Return full doc
const requisitionInDb: {
every: string,
field: number,
typed: string,
here: number
} = (await ctx.runQuery(internal.some.query, { ...args })) || {}
return requisitionInDb
@Drips where you at on this? First step is to look for all instances of ctx.run in your convex code. The source of that type error is generally going to be one of these. Do you have a lot of them?
Drips
DripsOP4w ago
Is 131 a lot ?😁
erquhart
erquhart4w ago
lol maybe - possibly a sign of an anti-pattern unless your project is really big or does a lot with external services I'd look at changes since the last time your code type checked properly to bring down the scope
Drips
DripsOP4w ago
Project is really big and also uses external services. 😁 As I’m refactoring from supabase to convex it’s kinda never “worked” I’m still in transition.
Eliot Gevers
Eliot Gevers4w ago
Migration from supabase to convex is hell, I saw they write some blog post recently. You might want to take a look at that.
Drips
DripsOP4w ago
I thought I did read that article but did not saw something about my problem. The fun part is. In my ide it’s an error in my local vercel build it’s an error but when I push to vercel it’s not a error 🫠
Gorka Cesium
Gorka Cesium3w ago
since I started vibecoding i also have a lot of these errors

Did you find this page helpful?