drizzle-orm: [BUG]: Broken typings on Visual Studio Code@1.91.0 using Typescript@5.5

What version of drizzle-orm are you using?

0.31.1

What version of drizzle-kit are you using?

0.22.2

Describe the Bug

After the update of Visual Studio Code to the latest (1.91.0) version, typescript started throwing errors like ones below, for every query. I am working in the nx monorepo, so I had to install typescript in the root of the project and use workspace version of typescript to fix the error messages, but that’s just a temporary fix. By default this version of VSC uses typescript 5.5, everything works fine on 5.4.

CleanShot 2024-07-08 at 21 01 01@2x

No overload matches this call.
  Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
    Argument of type 'PgColumn<{ name: "id"; tableName: "deal"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
      Types of property 'table' are incompatible.
        Property '[IsDrizzleTable]' is missing in type 'PgTable<TableConfig>' but required in type 'Table<TableConfig<Column<any, object, object>>>'.
  Overload 2 of 3, '(left: Aliased<string>, right: string | SQLWrapper): SQL<unknown>', gave the following error.
    Argument of type 'PgColumn<{ name: "id"; tableName: "deal"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<string>'.
      Type 'PgColumn<{ name: "id"; tableName: "deal"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<string>': sql, fieldAlias
  Overload 3 of 3, '(left: SQLWrapper, right: unknown): SQL<unknown>', gave the following error.
    Argument of type 'PgColumn<{ name: "id"; tableName: "deal"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'SQLWrapper'.
      The types returned by 'getSQL()' are incompatible between these types.
        Type 'import("/Users/nightspite/Code/polubee/node_modules/.pnpm/drizzle-orm@0.31.1_postgres@3.4.3/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type 'import("/Users/nightspite/Code/polubee/node_modules/.pnpm/drizzle-orm@0.31.1_react@18.2.0/node_modules/drizzle-orm/sql/sql").SQL<unknown>'.
          Types have separate declarations of a private property 'shouldInlineParams'.ts(2769)
table.d.cts(29, 5): '[IsDrizzleTable]' is declared here.

Expected behavior

No error warnings

Environment & setup

macos sonoma 14.4.1 vsc 1.91.0 typescript 5.5 node 20 pnpm 8.6.10 nx 19.2.2 eslint 8.55.0

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 19
  • Comments: 15

Most upvoted comments

I was able to solve this. Here’s my repo structure using turborepo and pnpm workspaces:

- apps
    - web
- packages
    - db

Previously:

  • I had schemas defined in the db package. I was referencing this package in the web app.
  • I added drizzle-orm as a dependency (not dev-dependency) to both db package (obviously) and web app (cause I need eq and and operators)
  • This caused issues in turborepo environment creating multiple entries of drizzle-orm package in the pnpm-lock.yaml file.

New setup:

  • I added exports from the db package itself (just like schema export). Example:
// packages/db/src/drizzle.ts
export { and, eq } from 'drizzle-orm`
  • I removed the drizzle-orm dependency from the web app and imported required operators from the db package itself.

Import changes done in web app:

Before

import { and, eq } from 'drizzle-orm'

After

import { and , eq } from '@repo/db/drizzle'

I have crossed check that this works in both development mode and production build for remix app

I was able to resolve this same issue by deleting the lockfile, removing the node_modules directory and reinstalling.

but it still got types errors if using callback like on where clause here:

const isUserExists = await dbDrizzle.query.userTable.findFirst({
    where: (user, { eq }) => eq(user.email, email),
});

the errors: image

but if the eq and userTable are imported from @repo/db it is working:

const isUserExists = await dbDrizzle.query.userTable.findFirst({
   where: eq(userTable.email, email),
});

i just want to let you know @L-Mario564, sorry for tagging😄

I was able to solve this. Here’s my repo structure using turborepo and pnpm workspaces:

- apps
    - web
- packages
    - db

Previously:

  • I had schemas defined in the db package. I was referencing this package in the web app.
  • I added drizzle-orm as a dependency (not dev-dependency) to both db package (obviously) and web app (cause I need eq and and operators)
  • This caused issues in turborepo environment creating multiple entries of drizzle-orm package in the pnpm-lock.yaml file.

New setup:

  • I added exports from the db package itself (just like schema export). Example:
// packages/db/src/drizzle.ts
export { and, eq } from 'drizzle-orm`
  • I removed the drizzle-orm dependency from the web app and imported required operators from the db package itself.

Import changes done in web app:

Before

import { and, eq } from 'drizzle-orm'

After

import { and , eq } from '@repo/db/drizzle'

I have crossed check that this works in both development mode and production build for remix app

I was able to solve this. Here’s my repo structure using turborepo and pnpm workspaces:

- apps
    - web
- packages
    - db

Previously:

  • I had schemas defined in the db package. I was referencing this package in the web app.
  • I added drizzle-orm as a dependency (not dev-dependency) to both db package (obviously) and web app (cause I need eq and and operators)
  • This caused issues in turborepo environment creating multiple entries of drizzle-orm package in the pnpm-lock.yaml file.

New setup:

  • I added exports from the db package itself (just like schema export). Example:
// packages/db/src/drizzle.ts
export { and, eq } from 'drizzle-orm`
  • I removed the drizzle-orm dependency from the web app and imported required operators from the db package itself.

Import changes done in web app:

Before

import { and, eq } from 'drizzle-orm'

After

import { and , eq } from '@repo/db/drizzle'

I have crossed check that this works in both development mode and production build for remix app

It works for me, thanks!!