ApsA
Convex Community5mo ago
1 reply
Aps

Static code generation <> WorkflowId

I have a project that is growing in lines of code. I am following all recommended convex practices of keeping all my functions strictly typed to minimise how much type inference typescript needs to make, but it still reached the point where it's becoming just too slow to work comfortably.

I found the Static code generation section in the docs (https://docs.convex.dev/production/project-configuration#using-static-code-generation-beta) which looks like exactly what I need. I tried it out and for the most part it works perfectly.

There is however an issue when paired with
@convex-dev/workflow
. Code generation does not work as expected for the
vWorkflowId
validator. I am typing my schema as follows:

...
activeWorkflowId: v.optional(vWorkflowId),
...


When I try to query this table without SCG, the type is as expected:
...
activeWorkflowId?: WorkflowId | undefined;
...


However, with SCG the type becomes a string:
...
activeWorkflowId?: string;
...


As far as I can tell this make it unusable at the moment because I have type errors in all places where I use the
vWorkflowId
validator and the
WorkflowId
type. Since this type is coming directly from
ctx.db.query
I am not sure how to work around it. Note that this issue is observed also in convex function arguments, which makes it impossible to correctly pass a function handler in the
onComplete
callback of workflows, since the
onComplete
expects
workflowId: vWorkflowId
but the resulting type from a function this argument resolves to
workflowId: string
after the Static Code Generation.

Overall this feature is very much needed as codebases are becoming larger, this is the only issue I observed so far that is preventing me from using it.
Configure your Convex project for development and production deployment using convex.json, environment variables, and deployment settings.
Project Configuration | Convex Developer Hub
Was this page helpful?