PrinceP
Convex Community2y ago
43 replies
Prince

Query type definition does not include all possible return scenarios

My query function is not returning all the possible values as a type definition (i.e. fullReportWithUser below), is this something I need to manually add with manual types or am I doing something wrong?

export const getReport = query({
  args: { reportId: v.id("reports") },
  handler: async (ctx, { reportId }) => {
    const user = await currentUser(ctx, {})
    const fullReport = await ctx.db.get(reportId)
    if (!fullReport) return null
    const { cost, recordingUrl, ...report } = fullReport
    if (user?.admin) {
      if (fullReport.userId) {
        const reportUser = await ctx.db.get(fullReport.userId)
        const fullReportWithUser = { ...fullReport, reportUser }
        return fullReportWithUser
      } else {
        return fullReport
      }
    } else {
      return report
    }
  },
})


Thanks
Was this page helpful?