Foreign key reference in drizzle causes type error

In my drizzle schema, I have two tables, users and payment_history, when I try to reference the id of payment_history, it throws a type error Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.. users table and payment_history table have a one to many relation where one user can have many payments. These are my schema definition: users:
export const users = pgTable("users",{
...
   last_payment_id: varchar("last_payment_id").references(() => payment_history.id, { onDelete: "cascade" }),//error
...
})

payment_history:

export const payment_history = pgTable("payment_history",{
   id: varchar("id").primaryKey().unique().notNull(),
...
   user_id: varchar("user_id").references(() => users.id, { onDelete: "cascade" }), //fk to users.id where i get type error
})


and these are the table relations: users:
export const userRelation = relations(users, ({ one, many }) => ({
...
   payment_history: many(payment_history),
...
}))
export const paymentHistoryRelations = relations(payment_history, ({ one, many }) => ({
...
   last_payment: one(users, {    
      fields: [payment_history.user_id],
      references: [users.last_payment_id],
   }),
...
}))
Was this page helpful?