Essentially, my goal is to determine the type of the result obtained from a FindUnique
operation in Prisma. The current return type is any
:
import prisma from "@/libs/prismaDb";
import { Prisma } from "@prisma/client";
export default async function getOrderById(orderId: string) {
try {
const order = await prisma.order.findUnique({
where: { id: orderId },
include: { address: {}, products: {} },
});
return order;
} catch (error: any) {
throw new Error(error);
}
}
export type OrderByIdQueryResult = Prisma.PromiseReturnType<
typeof getOrderById
>;
I attempted to use findUniqueOrThrow
, but it returns the type
$Result.GetResult<Prisma.$OrderPayload<ExtArgs>, T, "findUniqueOrThrow">
, which still doesn't provide proper linting for the order
result.