Perhaps this is more of a typescript question, but...
# prisma-client
m
Perhaps this is more of a typescript question, but if I have a model like this in Prisma:
existingListing: Listings & {
ListingPhotos: ListingPhotos[];
}
How do I instantiate (if that is the right word?) it on the client? Normally I would do something like this:
existingListing: Listings = []
But with the nested model, it doesn't work.
a
Hey @Matt Knight, do you have a specific use case or example you could provide?
m
Hi! Well, the use case is trying to cast the data from Prisma on Angular.... In terms of examples, I gave you the precise example I am trying to make work.. what additional context can I add?
a
A small reproduction of your example seems to work for me. Can you share the specific error you are getting?
m
@Austin I appreciate the help. I think the issue is how to instantiate it as empty.. So, if I were to do this:
existingListing: Listings & {
ListingPhotos: ListingPhotos[];
} = [];
Type 'undefined[]' is not assignable to type 'Listings & { ListingPhotos: ListingPhotos[]; }'. Type 'undefined[]' is missing the following properties from type 'Listings': ListingId, accountId, DateTimeListed, DateAvailable, and 31 more.ts(2322) Well, that makes sense, because I need the ListingPhotos Object. This is accepted by the typings:
existingListing: Listings & {
ListingPhotos: ListingPhotos[];
} = [][''];
But it isn't quite right... Anyway.. maybe it doesn't matter... casting to
any
works well enough.. just not ideal.