milk enjoyer
milk enjoyer2y ago

Generated types fall to default when using a schema with 200+ keys

I define all my tables with Zod and it is a great workflow. Using zodToConvex, I convert everything to convex validators before adding it to my defined schema. However, I realized that the generated types fall back to the following when I added around 200+ keys to my Zod schema:
{
[x: string]: Value;
_id: Id<"tableName">;
}
{
[x: string]: Value;
_id: Id<"tableName">;
}
Is this intended?
2 Replies
Aps
Aps4mo ago
Hey @milk enjoyer, are you still facing issues with the generated types? I'm not using Zod, but I do notice a lot of issues with the generated types. I try my best to define all my functions in the following structure to avoid circular references:
const operationArgs = v.object({ ... });
export async function operationFn(ctx: MutationCtx, args: Infer<typeof operationArgs>): TypedReturn { ... }
export const operation = mutation({
args: operationArgs,
handler: operation,
});
const operationArgs = v.object({ ... });
export async function operationFn(ctx: MutationCtx, args: Infer<typeof operationArgs>): TypedReturn { ... }
export const operation = mutation({
args: operationArgs,
handler: operation,
});
But still, my api oftern resolves to "any" and I need to change something in the file to get it to resolve correctly. It's not an issue with my IDE either. Running tsc will also resolve many api types as "any" and so I often have type errors that I just miss until I encounter them at runtime. Are you experiencing something similar?
ampp
ampp4mo ago
I generate a ton of types (not so much with zod yet) but this issue is usually some other problem in the code. I know several different causes its always best to try to address it as soon as it appears.

Did you find this page helpful?