[BUG]: Left Join PgColumn Incompatible After the Latest Version
Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
What version of drizzle-orm are you using?
0.43.x
What version of drizzle-kit are you using?
0.31.0
Other packages
No response
Describe the Bug
The issue started occurring from version 0.43.x onwards; it was working normally before that. It occurs when passing the user table in a join to service!
Code:
import { db } from '@repo/drizzle/index'
import { eq } from 'drizzle-orm'
import * as t from 'drizzle-orm/pg-core'
export const user = t.pgTable('users', {
id: t.integer().primaryKey().generatedAlwaysAsIdentity(),
name: t.varchar().notNull(),
})
export const service = t.pgTable('services', {
id: t.integer().primaryKey().generatedAlwaysAsIdentity(),
name: t.varchar().notNull(),
authorId: t
.integer('author_id')
.references(() => user.id, {
onUpdate: 'cascade',
})
.notNull(),
})
export const test = async () => {
await db.select().from(service).leftJoin(user, eq(service.authorId, user.id))
}
Error:
Argument of type 'PgTableWithColumns<{ name: "users"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; }; dialect:...' is not assignable to parameter of type 'SQL<unknown> | Subquery<string, Record<string, unknown>> | PgViewBase<string, boolean, ColumnsSelection> | PgTable<TableConfig>'.
Type 'PgTableWithColumns<{ name: "users"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; }; dialect:...' is not assignable to type 'PgTable<TableConfig>'.
The types of '_.config.columns' are incompatible between these types.
Type '{ id: PgColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; }' is not assignable to type 'Record<string, PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'.
Property 'id' is incompatible with index signature.
Type 'PgColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>' is not assignable to type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>'.
The types of 'table._.config.columns' are incompatible between these types.
Type 'Record<string, import("/home/william/github/turborepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_5b710c8e0a8bb205446dd39d33d33cc0/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("/home/william/github/turborepo/node_modules/.pnpm/drizzl...' is not assignable to type 'Record<string, import("/home/william/github/turborepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_5b710c8e0a8bb205446dd39d33d33cc0/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("/home/william...'.
'string' index signatures are incompatible.
Type 'import("/home/william/github/turborepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_5b710c8e0a8bb205446dd39d33d33cc0/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("/home/william/github/turborepo/node_modules/.pnpm/[email protected]_@p...' is not assignable to type 'import("/home/william/github/turborepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_5b710c8e0a8bb205446dd39d33d33cc0/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("/home/william/github/turbore...'.
Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.
Details: ts-error-translator
I’m running into the same problem after upgrading to [email protected].
Doing any kind of join results in a TypeScript type error that didn’t happen before.
I have the same issue with version 0.43.1. In version 0.42.0, this code worked well:
const clientsWithoutCreds = await db
.select()
.from(clients)
.leftJoin(creds, and(eq(clients.id, creds.clientId), eq(creds.key, "creds")))
.where(isNull(creds.key));
for (let c of clientsWithoutCreds) {
await db.delete(clients).where(eq(clients.id, c.clients.id));
deleted++;
}
After upgrading, the type of c.clients.id is strange and not compatible with clients.id on eq()
Same issue on my side: cannot upgrade to 0.43.x
Same issue on my side: cannot upgrade to 0.43.x
I get the same issue using MySQL and a monorepo. There seems to be typing changes to join https://github.com/drizzle-team/drizzle-orm/compare/0.42.0...0.43.1#diff-941bd29eda261190fe8bfd11132a27545b6b5fbdceb3ca2e50656ed47895f00c but I don't get why this cause issues.
@Sukairo-02 It must probably be some detail that you missed
Was someone able to find a workaround?
I faced the exact same "Property 'config' is protected but type 'Column<...>' is not a class derived from 'Column<...>'" error when using innerJoin (and it seems leftJoin as well, based on this issue). This started happening for me with Drizzle ORM 0.43.x.
What fixed it for me was changing my tsconfig.json:
- From:
{ "compilerOptions": { "module": "ESNext", "moduleResolution": "ESNext" } } - To:
{ "compilerOptions": { "module": "ES2015", // Also changed this "moduleResolution": "bundler" } }
My guess: This issue seems related to how TypeScript resolves Drizzle's type definitions. moduleResolution: "ESNext" (or similar Node strategies) might be causing conflicting or duplicate type inferences for PgTableWithColumns versus the PgTable expected by join methods. This leads to TypeScript seeing them as incompatible.
Switching to moduleResolution: "bundler" likely provides a more consistent type resolution, especially for how Drizzle ORM structures its types.
This tsconfig.json adjustment resolved the type incompatibility for me — though it feels more like a workaround than a real solution, and it’s probably only viable in a constrained setup like turborepo.
The solution @HirokiTakekuma presented sadly did not fix the issue for me
Any solution or workaround for this issue?
@yWilliamLima do you have a monorepo setup?
reproduced, fixing this issue at least trying
fixed in [email protected]
thank you so much
Still an issue in 0.44.3