How are people with handling types where the respo...
# orm-help
e
How are people with handling types where the response from a Prisma query is inferred? For example in the response from the following create, I want to explicitly type the response so that I can pass this throughout my application.
Copy code
// Inferred type:
// User & {
//   posts: Post[];
// }
const user = await prisma.user.create({
  data: {
    email: '<mailto:alice@prisma.io|alice@prisma.io>',
    password: '0ee4808f893b8e05bdd251048d5c4c8af8bb89403676dda95619841a481f8e87',
    name: 'Alice',
    posts: {
      create: {
        title: 'Learn how to use Prisma with TypeScript',
        content: '<https://www.prisma.io/docs/>',
      },
    },
  },
  include: {
    posts: true,
  },
})
1
n
Hi @Eric Simon 👋 You are looking for this guide which demonstrates how to get the return type when using variation of generated model types. Can you have a look and let me know if this solves the issue for you?
👀 1
s
Hello @Nurul, with my team we have a similar situation. We read the guide you linked and that helped us in some cases. What we are currently struggling with is the following: we would like to have a function that takes something like this as an argument:
User & { posts?: Post[], billingInfo?: BillingInfo, ... }
A type with all the relations without knowing in advance what relations were loaded by the caller. The function should perform some generic work on the user entity and other work on the relations only if they were included by the caller. Hope I made myself clear! Thank you!
n
Hey @Samuele Guerrini 👋 If I understand correctly you would essentially want a model type with all the relations loaded which would be optional, correct?
👍 1
s
Hi @Nurul, yes that is what we would like to have. We managed to do something with the guide you posted above: we wrote a funcion like "getFullUser" with all the relations included and exported its type. This is not very scalable for us because we have many "sub-relations". It would be perfect if adding a relation in the post entity from the prisma schema could reflect on the "fullUser" type without having to include it. Thank you for your reply!
n
@Samuele Guerrini Can you create a Feature Request for this use case? this could be beneficial for others as well.
👍 1
s
Will do, thank you very much for your time! @Nurul
🙏 1