Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: neondatabase/serverless generic type defaults cause type error #1945

Closed
evanshortiss opened this issue Feb 29, 2024 · 4 comments · Fixed by #2033
Closed

[BUG]: neondatabase/serverless generic type defaults cause type error #1945

evanshortiss opened this issue Feb 29, 2024 · 4 comments · Fixed by #2033
Assignees
Labels
bug Something isn't working

Comments

@evanshortiss
Copy link

evanshortiss commented Feb 29, 2024

What version of drizzle-orm are you using?

0.29.4

What version of drizzle-kit are you using?

No response

Describe the Bug

Configuring the Neon serverless driver (v0.9.0) with Drizzle ORM using the following code:

import { neon } from "@neondatabase/serverless"
import { drizzle } from "drizzle-orm/neon-http"

const sql = neon(process.env.DATABASE_URL!)
export const db = drizzle(sql)  // Error on this line

Produces this error:

Argument of type 'NeonQueryFunction<false, false>' is not assignable to parameter of type 'NeonQueryFunction<boolean, boolean>'.
  Types of property 'transaction' are incompatible.
    Type '<ArrayModeOverride extends boolean = false, FullResultsOverride extends boolean = false>(queriesOrFn: NeonQueryPromise<false, false, any>[] | ((sql: NeonQueryFunctionInTransaction<ArrayModeOverride, FullResultsOverride>) => NeonQueryInTransaction[]), opts?: HTTPTransactionOptions<...> | undefined) => Promise<...>' is not assignable to type '<ArrayModeOverride extends boolean = boolean, FullResultsOverride extends boolean = boolean>(queriesOrFn: NeonQueryPromise<boolean, boolean, any>[] | ((sql: NeonQueryFunctionInTransaction<ArrayModeOverride, FullResultsOverride>) => NeonQueryInTransaction[]), opts?: HTTPTransactionOptions<...> | undefined) => Promise...'.
      Types of parameters 'queriesOrFn' and 'queriesOrFn' are incompatible.
        Type '((sql: NeonQueryFunctionInTransaction<any, any>) => NeonQueryInTransaction[]) | NeonQueryPromise<boolean, boolean, any>[]' is not assignable to type '((sql: NeonQueryFunctionInTransaction<any, any>) => NeonQueryInTransaction[]) | NeonQueryPromise<false, false, any>[]'.
          Type 'NeonQueryPromise<boolean, boolean, any>[]' is not assignable to type '((sql: NeonQueryFunctionInTransaction<any, any>) => NeonQueryInTransaction[]) | NeonQueryPromise<false, false, any>[]'.
            Type 'NeonQueryPromise<boolean, boolean, any>[]' is not assignable to type 'NeonQueryPromise<false, false, any>[]'.
              Type 'NeonQueryPromise<boolean, boolean, any>' is not assignable to type 'NeonQueryPromise<false, false, any>'.
                Type 'boolean' is not assignable to type 'false'.ts(2345)

Expected behavior

Expected no type error. A workaround that might work for some folks is to define the generic when calling the neon function:

const sql = neon<boolean, boolean>(process.env.DATABASE_URL!)

Another workaround is to use drizzle-orm@0.28.

I think updating neon-http/driver.ts like so resolves the problem, but I'm not familiar with how Drizzle manages dependencies with pnpm, so honestly, I had some trouble performing a quick test against the new driver: 🫣

export function drizzle<ArrayMode extends boolean, FullResults extends boolean, TSchema extends Record<string, unknown> = Record<string, never>>(
	client: NeonQueryFunction<ArrayMode, FullResults>,
	config: DrizzleConfig<TSchema> = {},
): NeonHttpDatabase<TSchema>

Environment & setup

Node.js 18
TypeScript 5.3.3

@evanshortiss evanshortiss added the bug Something isn't working label Feb 29, 2024
@evanshortiss
Copy link
Author

Correction. I thought this was an issue with changes in the Neon driver, but I think it's a mixture. There's been a change on the Drizzle side too. My mistake.

@BinyangQin
Copy link

BinyangQin commented Feb 29, 2024

I got the same type error on learning todos tutorial, how to fix it?

@evanshortiss
Copy link
Author

evanshortiss commented Feb 29, 2024

@BinyangQin a temporary workaround is in my original post. Adding <boolean, boolean> fixes it for me:

const sql = neon<boolean, boolean>(process.env.DATABASE_URL!)

Edit: Drizzle v0.28 also works OK.

@kashalls
Copy link

@BinyangQin a temporary workaround is in my original post. Adding <boolean, boolean> fixes it for me:

const sql = neon<boolean, boolean>(process.env.DATABASE_URL!)

Edit: Drizzle v0.28 also works OK.

This fixes the warning for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
4 participants