Type issue when creating self join

I have the following:

export const medusaCategories = sqliteTable("medusa_categories", {
  id: text("id").unique(),
  createdAt: text("created_at")
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: text("updated_at").default(sql`CURRENT_TIMESTAMP`),
  deletedAt: text("deleted_at"),
  // relations
  storeId: text("store_id")
    .references(() => medusaStores.id)
    .notNull(),
  parentId: text("parent_id").references(() => medusaCategories.id).notNull(),
});


If I comment out parentId then I get the type for medusaCategories. Otherwise I get the error:

'medusaCategories' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer

How to resolve? Thanks
Was this page helpful?