Self referencing column breaks table type in typescript

I have the following table:
export const categoriesTable = pgTable(
    'categories',
    {
        id: uuid('id').primaryKey(),
        name: varchar('name', { length: 50 }).notNull(),
        description: text('description'),
        parentId: uuid('parent_id').references(() => categoriesTable.id, { onDelete: 'set null' }),
        createdAt: timestamp('created_at').defaultNow()
    },
    (table) => ({
        nameIdx: uniqueIndex('name_idx').on(table.name)
    })
)


However typescript infers the type of categoriesTable as
any

It's only when I remove .references(() => categoriesTable.id, { onDelete: 'set null' }) that typescript infers the type correctly

If so, how can I still create a self reference in this case?
Was this page helpful?