Conditional Select in M2M findMany Type Inference

hey there, I'm adding a method that allows the user to either get a list of objects, and sometimes get related objects al well (members). it works fine function-wise - but for some reason, the addition of the ternary doesn't give me any type hints. I'd assume it'll add them conditionally... Is this a bug? am I missing anything? here is my code's paraphrase:
return db.query.projects.findMany({
columns: {
id: true
},
with: {
membersMapping: {
columns: {
memberId: true,
},
//** this makes the type inference crazy!
with: withMembers ? { member: { columns: { name: true, age: true } } } : {}
}
}
})
return db.query.projects.findMany({
columns: {
id: true
},
with: {
membersMapping: {
columns: {
memberId: true,
},
//** this makes the type inference crazy!
with: withMembers ? { member: { columns: { name: true, age: true } } } : {}
}
}
})
1 Reply
Angelelz
Angelelz12mo ago
Typescript usually does a good job inferring types but in this case you might need to either annotate the type or wrap this code in a generic function from which the final type can be inferred
Want results from more Discord servers?
Add your server