drizzle-team / drizzle-team/drizzle-orm

[BUG]: Typing breaks after 3 levels of nested joins

Open
#1,546 2 comments 0 reactions 0 assignees View on GitHub
improvement qb/crud qb/joins
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.29.0

### What version of `drizzle-kit` are you using?

_No response_

### Describe the Bug

If I have a query with more than 3 levels of nested joins, the type for the item of the nested joins becomes `{type: string}: unknown`.

```ts
const tableA = pgTable("table_a", {
id: varchar("id").primaryKey()
});

const tableB = pgTable("table_b", {
id: varchar("id").primaryKey(),
field2: varchar("field2")
});

const tableC = pgTable("table_c", {
id: varchar("id").primaryKey(),
field3: varchar("field3")
});

const parentTable = pgTable("parent", {
...
});

const q3 = db.select().from(tableC).innerJoin(tableB, eq(tableC.id, tableB.id)).as("q3");
const q2 = db.select().from(tableA).innerJoin(q3, eq(tableA.id, q3.id)).as("q2");
const q = db.select().from(parentTable).innerJoin(q2, eq(parentTable.id, q2.id);

const resp = await q;
resp.q2 // { [x: string]: unknown }
resp.parent // schema of parent table

### Expected behavior

Typing should accurately reflect the joined tables.

### Environment & setup

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.