drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Broken typings on Visual Studio [email protected] using [email protected]

Open nightspite opened this issue 1 year ago • 6 comments
trafficstars

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/[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type 'import("/Users/nightspite/Code/polubee/node_modules/.pnpm/[email protected][email protected]/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

nightspite avatar Jul 08 '24 19:07 nightspite

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

jkbudde avatar Jul 14 '24 19:07 jkbudde

I'm also having this issue. Its surprising that this still has not been adddressed to date :(

ironheart122 avatar Aug 18 '24 11:08 ironheart122

+1

Einsight04 avatar Aug 18 '24 20:08 Einsight04

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

Just stating the obvious here: THis didn't work for me.

ironheart122 avatar Aug 19 '24 03:08 ironheart122

https://github.com/drizzle-team/drizzle-orm/issues/2418#issuecomment-2297028615

ironheart122 avatar Aug 19 '24 17:08 ironheart122

Tried all the above, did not work. Downgrading VSCode to 1.90 worked though: https://code.visualstudio.com/updates/v1_90

alan-funded avatar Sep 24 '24 19:09 alan-funded

Same issue. No possible solution found so far.

jainmohit2001 avatar Oct 18 '24 19:10 jainmohit2001

Still an issue guys. This issue is months old with no fix

kylesloper avatar Oct 22 '24 20:10 kylesloper

I think I may be experiencing something similar

image
Argument of type '() => SQL' is not assignable to parameter of type 'string | SQL<unknown> | (() => SQL<unknown>)'.
  Type '() => SQL' is not assignable to type '() => SQL<unknown>'.

umsurething avatar Oct 26 '24 15:10 umsurething

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

jainmohit2001 avatar Oct 28 '24 08:10 jainmohit2001

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!!

makeryi avatar Oct 29 '24 13:10 makeryi

Upgrading to pnpm@9 worked for me. I also deleted pnpm-lock.yaml

rclmenezes avatar Nov 14 '24 23:11 rclmenezes

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😄

mamlzy avatar Nov 21 '24 03:11 mamlzy

@jainmohit2001 thank you. I also have exact setup and your solution works.

I'm curios. How did you debug and came to conclusion?

arbaaz avatar Jan 17 '25 05:01 arbaaz

Also facing this issue, re-exporting it in the db package in a monorepo seems to make the type errors go away, but this seems to be anti-pattern compared to what Turborepo recommends - installing dependencies in each app/package where they are used.

"drizzle-orm": "^0.41.0",
"drizzle-zod": "0.5.1",

chanmathew avatar Mar 22 '25 16:03 chanmathew

Hey everyone!

I've created this message to send in a batch to all opened issues we have, just because there are a lot of them and I want to update all of you with our current work, why issues are not responded to, and the amount of work that has been done by our team over ~8 months.

I saw a lot of issues with suggestions on how to fix something while we were not responding – so thanks everyone. Also, thanks to everyone patiently waiting for a response from us and continuing to use Drizzle!

We currently have 4 major branches with a lot of work done. Each branch was handled by different devs and teams to make sure we could make all the changes in parallel.


First branch is drizzle-kit rewrite

All of the work can be found on the alternation-engine branch. Here is a PR with the work done: https://github.com/drizzle-team/drizzle-orm/pull/4439

As you can see, it has 167k added lines of code and 67k removed, which means we've completely rewritten the drizzle-kit alternation engine, the way we handle diffs for each dialect, together with expanding our test suite from 600 tests to ~9k test units for all different types of actions you can do with kit. More importantly, we changed the migration folder structure and made commutative migrations, so you won't face complex conflicts on migrations when working in a team.

What's left here:

  • We are finishing handling defaults for Postgres, the last being geometry (yes, we fixed the srid issue here as well).
  • We are finishing commutative migrations for all dialects.
  • We are finishing up the command, so the migration flow will be as simple as drizzle-kit up for you.

Where it brings us:

  • We are getting drizzle-kit into a new good shape where we can call it [email protected]!

Timeline:

  • We need ~2 weeks to finish all of the above and send this branch to beta for testing.

Second big branch is a complex one with several HUGE updates

  • Bringing Relational Queries v2 finally live. We've done a lot of work here to actually make it faster than RQBv1 and much better from a DX point of view. But in implementing it, we had to make another big rewrite, so we completely rewrote the drizzle-orm type system, which made it much simpler and improved type performance by ~21.4x:
(types instantiations for 3300 lines production drizzle schema + 990 lines relations)

TS v5.8.3: 728.8k -> 34.1k
TS v5.9.2: 553.7k -> 25.4k

You can read more about it here.

What's left here:

Where it brings us:

  • We are getting drizzle-orm into a new good shape where we can call it [email protected]!

Breaking changes:

  • We will have them, but we will have open channels for everyone building on top of drizzle types, so we can guide you through all the changes.

Third branch is adding support for CockroachDB and MSSQL dialects

Support for them is already in the alternation-engine branch and will be available together with the drizzle-kit rewrite.

Summary

All of the work we are doing is crucial and should be done sooner rather than later. We've received a lot of feedback and worked really hard to find the best strategies and decisions for API, DX, architecture, etc., so we can confidently mark it as v1 and be sure we can improve it and remain flexible for all the features you are asking for, while becoming even better for everyone building on top of the drizzle API as well.

We didn't want to stay with some legacy decisions and solutions we had, and instead wanted to shape Drizzle in a way that will be best looking ahead to 2025–2026 trends (v1 will get proper effect support, etc.).

We believe that all of the effort we've put in will boost Drizzle and benefit everyone using it.

Thanks everyone, as we said, we are here to stay for a long time to build a great tool together!

Timelines

We are hoping to get v1 for drizzle in beta this fall and same timeline for latest. Right after that we can go through all of the issues and PRs and resond everyone. v1 for drizzle should close ~70% of all the bug tickets we have, so on beta release we will start marking them as closed!

AndriiSherman avatar Aug 30 '25 18:08 AndriiSherman

Hi team,

I’m running into a similar issue and wanted to provide some context from my setup. When I try to run a query using Drizzle ORM, I get the following TypeScript error:

Image

Example code causing the issue: const session = await db.query.userSessions.findFirst({ where: (s, { eq, and }) => and(eq(s.id, decoded.sessionId), eq(s.userId, decoded.userId)), });

and it's only giving me warnings for queries like this. Another example: const user = await db.query.users.findFirst({ where: (u, { eq }) => eq(u.email, email), });

another example: const requester = await db.query.users.findFirst({ where: (u, { eq }) => eq(u.id, requesterId), columns: { id: true, role: true, department: true } });

My setup:

  • Windows 10 / OneDrive synced project
  • TypeScript 5.9.2 installed globally and locally in node_modules
  • [email protected] and [email protected]
  • VSCode as IDE, using the workspace TS version (or attempting to - both global and workspace don't resolve the issue)
  • tsconfig.json with "skipLibCheck": true and "strict": true

I suspect the issue is related to TypeScript 5.5 strict type checks and private properties in SQL, because:

  1. The error points to duplicate SQL types, even though I only have one drizzle-orm version installed.
  2. It seems like VSCode or TypeScript is treating the SQL type as two separate types because of the private property shouldInlineParams.
  3. Moving the project off OneDrive and reinstalling dependencies didn’t resolve it.

It would be great to get confirmation if this is indeed a TypeScript >5.5 compatibility issue, or if there’s a recommended workaround aside from downgrading TypeScript. Thanks!

haider-sama avatar Sep 24 '25 02:09 haider-sama