How to define type of table with all relations included?

Say I have a a table users and a user has many posts, so I define a relationship as shown in the docs

If I want to define a type that is "user with posts" that would be the result of:
await db.query.user.findFirst({ with: { posts: true } });

the type of this would be something like
type UserWithPosts = (typeof users._.inferSelect) & {posts: Array<typeof posts._.inferSelect>}


Is there a cleaner way to define that where all the relations are just included and automatically inferred?
Was this page helpful?