conditional select return wrong type

const registeree = (getCount?: boolean) => {
        return tx
          .select({
            ...(getCount ? { total: count() } : {}),
          })
          .from(eventHasParticipant)
          .innerJoin(events, eq(eventHasParticipant.eventId, events.id))
          .innerJoin(
            participants,
            eq(eventHasParticipant.participantId, participants.id)
          )
          .where(and(eq(events.id, eventID), eq(events.createdBy, createdBy)));
      };

      const total = await registeree(true).limit(limit).offset((page - 1) * limit);
      const registereeResult = await registeree();

      total[0].total = total[0].total || 0;

      return { total: total[0].total, registereeResult };

so I've tried using conditional select query, so that i'm able to reuse my query syntax without repeating to get the rows and the count, I'm not sure where I'm wrong at be when I do this the registereeResult would return this object instead

const registereeResult: {
    total?: number | undefined;
}[]
Was this page helpful?