Next.js Discord

Discord Forum

How do you solve this typescript thing

Unanswered
Common House-Martin posted this in #help-forum
Open in Discord
Common House-MartinOP
Typescript question. So I'm using prisma right, In prisma you get the default interfaces for each model from prisma/client but if I'm expecting a type that has an included model property inside it I need to make a new interface expecting that joined property. This works but my question is if there's a better way of doing it , is this a good approach or maybe this will make refactoring harder in the long run?

I'll show an example of how I do it nowadays
import type { Box, Movement, User } from "@prisma/client";

export interface MovementWithAuthor extends Movement {
  createdBy: User
}
export interface BoxWithMovementsAndAuthors extends Box {
  movements: MovementWithAuthor[]
}

0 Replies