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]: Using sql.placeholder with limit and/or offset for a prepared statement produces TS error #2146

Closed
vince-winkintel opened this issue Apr 10, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@vince-winkintel
Copy link

What version of drizzle-orm are you using?

0.30.7

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

Given the following code,

const database: PlanetScaleDatabase = drizzle(client);
const prepared = database
    .select()
    .from(product)
    .orderBy(product.name)
    .limit(sql.placeholder('limit'))
    .offset(sql.placeholder('offset'))
    .prepare();

TypeScript will throw an error on the use of sql.placeholder for both limit() and offset() functions. The exact message is:

Argument of type 'Placeholder<"limit", any>' is not assignable to parameter of type 'number'.ts(2345)

Argument of type 'Placeholder<"offset", any>' is not assignable to parameter of type 'number'.ts(2345)

A workaround is to use the as never assertion to defer type inference and successfully compile.

...
    .limit(sql.placeholder('limit') as never)
    .offset(sql.placeholder('offset') as never)
    .prepare();

Expected behavior

No typescript error when using sql.placeholder with limit and/or offset for a prepared statements.

Environment & setup

No response

@vince-winkintel vince-winkintel added the bug Something isn't working label Apr 10, 2024
@lovrozagar
Copy link

Up

@AndriiSherman
Copy link
Member

was fixed in drizzle-orm@0.36.1

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
None yet
Development

No branches or pull requests

3 participants