How to get the return Type of a query with relations?

  • Imagine having 2 tables: Posts and Users
  • there is a relation between Posts and users, since 1 user can write several posts. So we define this relation.
  • now I write a query to retrieve the user and all his/her posts with the syntax:```const user = await db.query.findFirst({where: .....with: { posts: true}});```How can I "extract" / "infer" the type of `user` beforehand?My goal is to be able to write something like:```class myStore {public user: UserWithPosts;loadUser(id: number){ this.user = await db.query.findFirst({ where: ..... with: { posts: true } }); }}```
wondering.gif
Was this page helpful?