Help with Prisma Validator static evaluation

I am trying to build a helper function that will allow me to abstract away some deeply nested includes for a data type. However I'm trying to make this reusable like in the following snippet
export const helper = (include: boolean) => {
return Prisma.validator<Prisma.SomeInclude>()({
include: {
someTable: include
}
})
export const helper = (include: boolean) => {
return Prisma.validator<Prisma.SomeInclude>()({
include: {
someTable: include
}
})
The issue with this is that I wish it would correctly map when passing true to { include: { someTable: true } }. Any wizards that could help?
2 Replies
Liam
Liam2y ago
I am not sure I follow, could you elaborate?
bcangussu
bcangussuOP2y ago
Sure. The issue I'm having is that if I use the helper as shown above in a query I get partial types, because it maps to
{ include: {someTable: boolean}}
{ include: {someTable: boolean}}
I'd like it to, for example:
const values = await prisma.table,findMany({
include: helper(true)
})
const values = await prisma.table,findMany({
include: helper(true)
})
and have the result be Table & {someTable: ItsType} when I pass true, it currently returns Table & {someTable?: ItsType}
Want results from more Discord servers?
Add your server