louis-sanna-eki
04/22/2022, 9:20 PMinterface CrudServices<T> {
getDocument: (id: number) => Promise<T>;
}
function buildCrudServices<T>(model): CrudServices<T> {
const getDocument = (id: number): Promise<T> =>
model.findUnique({ where: { id } });
return { getDocument };
}
How do I type model? Each of my model have costum type in the prisma client.Nurul
04/25/2022, 9:44 AMlouis-sanna-eki
04/25/2022, 11:56 AMDo you wish to get types which are generated by Prisma from your models?yes and no. I have several model, for instance
prisma.users
et prisma.teams
, and I want to create a common function that build crud operation from those model. So I want a type which is valid for prisma.users
and prisma.team
.
For Mongoose it could be done with the Model<T>
interface (see https://github.com/Automattic/mongoose/blob/master/types/index.d.ts#L261). I don't find a similar type for prisma.