drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.44k stars 484 forks source link

[BUG]: Partial Insert returning expected 0 arguments #2496

Open josepdecid opened 2 weeks ago

josepdecid commented 2 weeks ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

I have the following code snippet:

const recordId = await db
    .insert(organizationsTable)
    .values({ clerkId: 'whatever-id' })
    .returning({ id: organizationsTable.id });

After an insert, I'm trying to return a value with partial insert returning. However, TS is complaining that returning "Expected 0 arguments, but got 1.":

CleanShot 2024-06-12 at 17 41 02@2x

Removing the partial return and simply returning the whole thing does not complain at all and works as expected:

const recordId = await db
    .insert(organizationsTable)
    .values({ clerkId: 'whatever-id' })
    .returning();

I initially thought it was a problem with VSCode so I tried to restart TS server, make sure that it matches the project's TS version and so on, but it also fails when I do the build step.

Navigating to source I can see that both function definitions exist:

returning(): PgInsertWithout<PgInsertReturningAll<this, TDynamic>, TDynamic, 'returning'>;
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): PgInsert...

Expected behavior

It should allow me to pass an argument to select the fields I want to return.

Environment & setup

No response