pgEnum conversion not working as expected

I have the following pgEnum defined:

export const ApprovalRequestTypePgEnum = pgEnum('approval_request_type', ['CREDIT_NOTE']);

(Yes, there'll be more types later). My schema is:

export const approvalRequestsTable = pgTable('approval_requests', {
  id: uuid('id').default(sql`gen_random_uuid()`).primaryKey().notNull(),
  requestorId: integer('requestor_id').notNull().references(() => employeesTable.workerId),
  type: ApprovalRequestTypePgEnum('type').notNull(),
  approvalObjectId: uuid('approval_object_id').notNull(),
  status: ApprovalStatusPgEnum('status').notNull(),
  totalValue: integer('total_value').notNull(),
  currencyCode: text('currency_code').notNull(),
});


However when I do:

export const insertApprovalRequest = async (approvalRequest: ApprovalRequestInput): Promise<ApprovalRequest> => {
  logger.info('Inserting approval request', { approvalRequest });
  const insertedApprovalRequest = await db
    .insert(approvalRequestsTable).values({
      ...approvalRequest,
      type: ApprovalRequestType.CREDIT_NOTE
    }).returning().then((res) => res[0]);
  logger.info('Inserted approval request', { insertedApprovalRequest });

  return getApprovalRequest(insertedApprovalRequest.id) as Promise<ApprovalRequest>;
};


I get the error ERROR: column \"type\" is of type approval_request_type but expression is of type text; Hint: You will need to rewrite or cast the expression.

How can I solve this? My ApprovalRequestType enum is also mapped to 'CREDIT_NOTE'
Was this page helpful?