Prisma Types

Pls somebody help with these types
type PostFindUniqueResult = Prisma.Result<
typeof db.post,
{
where: {
id: string;
};
include: {
author: true;
tags: true;
comments: {
include: {
author: true;
};
};
};
},
'findUnique'
>;

let post: PostFindUniqueResult;

post = await PostModel.findUnique({
where: {
id: params.id,
},
include: {
author: true,
tags: true,
comments: {
include: {
author: true,
},
},
},
});
type PostFindUniqueResult = Prisma.Result<
typeof db.post,
{
where: {
id: string;
};
include: {
author: true;
tags: true;
comments: {
include: {
author: true;
};
};
};
},
'findUnique'
>;

let post: PostFindUniqueResult;

post = await PostModel.findUnique({
where: {
id: params.id,
},
include: {
author: true,
tags: true,
comments: {
include: {
author: true,
},
},
},
});
I am getting error that the type PostFindUniqueResult is not the same as the return type from PostModel.findUnique
2 Replies
bockster6669
bockster66693w ago
same as this one and so on
type PostFindManyResult = Prisma.Result<
typeof db.post,
{
include: {
tags: {
select: {
name: true,
},
},
},
},
'findMany'
>;

const posts:PostFindManyResult = await PostModel.findMany({
include: {
tags: {
select: {
name: true,
},
},
},
});
type PostFindManyResult = Prisma.Result<
typeof db.post,
{
include: {
tags: {
select: {
name: true,
},
},
},
},
'findMany'
>;

const posts:PostFindManyResult = await PostModel.findMany({
include: {
tags: {
select: {
name: true,
},
},
},
});
PostFindUniqueResult is the correct type, but PostModel.findMany doesnt return it PostModel.findMany return only Post[] instead of Post[] & Tag: {name: string}
Dkyc
Dkyc3w ago
hello. try it like this
const postWithUser = Prisma.validator<Prisma.PostDefaultArgs>()({
include: {
User: true
}
});
export type PostWithUser = Prisma.PostGetPayload<typeof postWithUser>;
const postWithUser = Prisma.validator<Prisma.PostDefaultArgs>()({
include: {
User: true
}
});
export type PostWithUser = Prisma.PostGetPayload<typeof postWithUser>;
Want results from more Discord servers?
Add your server