circular foreign keys

I have separate files for each table:
export const productVariant = pgTable("product_variant", {
  id: serial("id").primaryKey(),
  defaultPackageSizeId: integer("default_package_size_id")
    .notNull()
    .references(() => packageSize.id),
});


export const packageSize = pgTable("package_size", {
  id: serial("id").primaryKey(),
  productVariantId: integer("product_variant_id").references(
    () => productVariant.id
  ),
});

but this does not work, error:
packageSize implicitly has type 
 because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

How to fix it?
Solution
  defaultPackageSizeId: integer("default_package_size_id").references(
    (): AnyPgColumn => packageSize.id
  ),
Was this page helpful?