© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•14mo ago•
2 replies
M Zeeshan

nested select type issue

hello there...
this code returns desired restuls but i have type issues
await db
    .select({
      ...getTableColumns(productTable),
      variant: {
        ...getTableColumns(variantTable),
        size: getTableColumns(sizeTable),
        color: getTableColumns(colorTable),
      },
      brand: getTableColumns(brandTable),
      category: getTableColumns(categoryTable),
    })
    .from(productTable)
    .where(eq(productTable.id, +id))
    .leftJoin(
      variantTable,
      eq(variantTable.product_id, productTable.id),
    )
    .leftJoin(brandTable, eq(brandTable.id, productTable.brand_id))
    .leftJoin(
      categoryTable,
      eq(categoryTable.id, productTable.category_id),
    )
    .leftJoin(colorTable, eq(colorTable.id, variantTable.color_id))
    .leftJoin(sizeTable, eq(sizeTable.id, variantTable.size_id));
await db
    .select({
      ...getTableColumns(productTable),
      variant: {
        ...getTableColumns(variantTable),
        size: getTableColumns(sizeTable),
        color: getTableColumns(colorTable),
      },
      brand: getTableColumns(brandTable),
      category: getTableColumns(categoryTable),
    })
    .from(productTable)
    .where(eq(productTable.id, +id))
    .leftJoin(
      variantTable,
      eq(variantTable.product_id, productTable.id),
    )
    .leftJoin(brandTable, eq(brandTable.id, productTable.brand_id))
    .leftJoin(
      categoryTable,
      eq(categoryTable.id, productTable.category_id),
    )
    .leftJoin(colorTable, eq(colorTable.id, variantTable.color_id))
    .leftJoin(sizeTable, eq(sizeTable.id, variantTable.size_id));

error
Type '{ id: PgColumn<{ name: "id"; tableName: "sizes"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; store_id: PgColumn<...>; }' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>'.
  Type '{ id: PgColumn<{ name: "id"; tableName: "sizes"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; store_id: PgColumn<...>; }' is missing the following properties from type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>': table, _, keyAsName, primary, and 18 more.ts(2322)
Type '{ id: PgColumn<{ name: "id"; tableName: "sizes"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; store_id: PgColumn<...>; }' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>'.
  Type '{ id: PgColumn<{ name: "id"; tableName: "sizes"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; store_id: PgColumn<...>; }' is missing the following properties from type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>': table, _, keyAsName, primary, and 18 more.ts(2322)
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Nested SQL select returning [x: string]: unknown type
Drizzle TeamDTDrizzle Team / help
2y ago
Nested records using select()
Drizzle TeamDTDrizzle Team / help
3mo ago
Select<Type> Help
Drizzle TeamDTDrizzle Team / help
2y ago