© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
3 replies
Steven

Nested "with" queries infer type "any"

The types for my queries with relations, are not inferred, and instead are always typed as "any".

So for example, what's mentioned in the docs...

const users = await db.query.users.findMany({
  with: {
    posts: {
      with: {
        comments: true,
      },
    },
  },
});
const users = await db.query.users.findMany({
  with: {
    posts: {
      with: {
        comments: true,
      },
    },
  },
});


"For any nested with queries Drizzle will infer types using Core Type API."

...this does not seem to happen for me. For none of my queries. So the example above, posts and comments would both be inferred as type "any".

I have properly defined and exported my schema, including tables and relations.

I have successfully generated and run migrations.

I am able to run my nested with queries and the relations are properly returned, so no issues there either.

Furthermore, I don't remember this not working when I first started my project, and I exported a couple of tables and relations from a single file.

Does anyone have an idea what might be going wrong?

https://orm.drizzle.team/docs/rqb
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Nested queries
Drizzle TeamDTDrizzle Team / help
2y ago
nested relation queries
Drizzle TeamDTDrizzle Team / help
3y ago
Infer Type from PgEnum
Drizzle TeamDTDrizzle Team / help
3y ago
drizzle-zod type infer
Drizzle TeamDTDrizzle Team / help
3y ago