skip to Main Content

I have a model with a relation to a separate model. I’m now querying the object and the related object. But how do I get a typescript type so that I can pass this object to subcomponents of my react component?

This only give me the Event type without the nested Owner property/relation.

import { Event, Prisma } from "@prisma/client";

type EventDetailsProps = {
  event: Event;
};

And this is not working too:

type EventDetailsProps = {
  event: Prisma.EventInclude;
};

2

Answers


  1. Chosen as BEST ANSWER

    I solved it this way:

    type EventDetailsProps = {
      event: Prisma.EventGetPayload<{ include: { owner: true } }>;
    };
    

    More details here.


  2. try Prisma.EventFieldRefs

    however you will have to overwrite relations fields as they are of String type. Otherwise read more

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search