panzacoderP
Convex Community11mo ago
1 reply
panzacoder

Nested convex folders & Type inference

So I've been trying to organize my projects better and really liked that we could nest folders in convex, allowing me to break up schemas/queries/mutations, etc by entity or concern, rather than just a flat folder.

This works well in general, allowing something like
api.users.getUser
to become
api.users.queries.getUser
. BUT, there is a huge drawback to this approach: Typescript inference becomes entirely generic for me when folders are nested, meaning I lose all type safety in my frontend queries.

For instance, I have a file
convex/auth.ts
and also
convex/users/functions.ts
. These both work in my frontend, but when introspecting the type of the
api
object, we get very different results (see screenshot 1)

Similarly the result of a function call from the
auth.ts
file is type-safe (screenshot 2)
While the result of a function call from the
users/functions.ts
file is always
any
(screenshot 3)

Is this just a limitation of the type inferences that are set up, or is there something more I can do to better enable type inference here?
CleanShot_2025-05-05_at_15.57.092x.png
CleanShot_2025-05-05_at_15.58.362x.png
CleanShot_2025-05-05_at_15.59.542x.png
Was this page helpful?