赛博鸭
赛博鸭2y ago

Type instantiation is excessively deep and possibly infinite

G'day! For past two days i'm thinking how to solve an issue with queries and stuff like that. The issue is when I'm using useQuery. or anything other, i'm getting error with api with a message called Type instantiation is excessively deep and possibly infinite. Any ideas how to fix it?
12 Replies
ballingt
ballingt2y ago
Sounds frustrating to have this problem for several days! This issue is usually caused by a syntax error in a Convex function or a Convex action that uses ctx.runMutation, ctx.runAction, or ctx.runQuery for type inference.
赛博鸭
赛博鸭OP2y ago
okay, so maybe I can return to 1.2.1? Might help i guess
ballingt
ballingt2y ago
No, changing the version of Convex shouldn't help. This is an issue with your queries, mutations, or actions in your convex/ folder.
赛博鸭
赛博鸭OP2y ago
well, my functions are not problem. For example:
export const find = query({
args: {
userId: v.string(),
},
handler: async (ctx, args) => {
return await ctx.db.query("profile").filter((q) => q.eq(q.field("userId"), args.userId)).unique();
}
})
export const find = query({
args: {
userId: v.string(),
},
handler: async (ctx, args) => {
return await ctx.db.query("profile").filter((q) => q.eq(q.field("userId"), args.userId)).unique();
}
})
which does not have any problems
ballingt
ballingt2y ago
If you open up convex/generated/api.d.ts are any of the imports broken? (underlined in red)
赛博鸭
赛博鸭OP2y ago
no, i don't see any
ballingt
ballingt2y ago
Unfortunately an error in one of these functions can cause this problem in all of them — so you need to check them all could you share your code? feel free to DM
Michal Srb
Michal Srb2y ago
With a lot (a lot) of code this might not be caused by errors. To get around it type annotate the return type of your functions (especial actions using runQuery/runMutation). But wrong imports/empty files inside convex are more likely.
Indy
Indy2y ago
Yea this happened to me recently. Looking through my notes I had a bad import statement in one of my convex query files.
ballingt
ballingt2y ago
We looked at this together, turns out it was some empty files in convex/ empty files aren't valid modules so TypeScript was sad. We'll look at improving the error message here.
赛博鸭
赛博鸭OP2y ago
I was thinking maybe there's some rules that can be disabled for a compiler? Like some eslint errors
Rispy
Rispy17mo ago
I ran into same issue and don't have idea how to fix it no empty files in convex dir

Did you find this page helpful?