drizzle-team / drizzle-team/drizzle-orm

[BUG]: `sql.placeholder` throws type error for enums

Open
#1,608 2 comments 0 reactions 1 assignee Claimed by @Angelelz View on GitHub
bug db/postgres priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.29.1

### What version of `drizzle-kit` are you using?

0.20.6

### Describe the Bug

`sql.placeholder` throws type error for enums.

```ts
import { drizzle } from "drizzle-orm/mysql2"
import { mysqlTable, varchar, mysqlEnum } from "drizzle-orm/mysql-core"
import { sql, SQL } from "drizzle-orm"

const statuses = ["PENDING", "ACCEPTED", "DECLINED"] as const

const status = mysqlEnum("status", statuses)
.notNull()
.default("PENDING")

type Status = typeof status

const tableA = mysqlTable("table_a", {
id: varchar("id", { length: 30}).primaryKey(),
status: status
});

const db = drizzle({} as any)

db.update(tableA).set({ status: sql.placeholder("status") })
```

the last line, `db.update(tableA).set({ status: sql.placeholder("status") })` throws a type error and a workaround is to type cast like so:

`db.update(tableA).set({ status: sql.placeholder("status") as unknown as SQL })`

for reference, @Angelelz asked me to open an issue for it in this discord discussion https://discord.com/channels/1043890932593987624/1181229913798357032

### Expected behavior

handle enum types correctly.

In general, it would be awesome to get actual type safety with prepared statements. I love the performance improvements, but the missing type safety really bums me out and makes the dev experience very error prone.

### Environment & setup

macos
bun
next 14

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.