© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
2 replies
Paul

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(),
});
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
'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
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Self join breaks return type
Drizzle TeamDTDrizzle Team / help
13mo ago
An issue when creating string[] elements
Drizzle TeamDTDrizzle Team / help
2y ago
Self-Join on a CTE
Drizzle TeamDTDrizzle Team / help
2y ago