drizzle-team / drizzle-team/drizzle-orm

[BUG]: some filter definitions could use the addition of the `undefined` type

Open
#3,733 0 comments 0 reactions 0 assignees View on GitHub
bug priority qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [X] I have verified that the bug I'm about to report hasn't been filed before.

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

0.38.0

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

0.30.0

### Other packages

pg@8.13.1, dotenv@16.4.7, tsx@4.19.2, @types/pg@8.11.10

### Describe the Bug

Currently a handful of types in `query-builders/insert.d.ts` have filters defined as `where?: SQL` or `setWhere?: SQL` instead of `where?: SQL | undefined` and `setWhere?: SQL | undefined`.

When using a stricter tsconfig that enables `exactOptionalPropertyTypes`, this is a faulty type since it fails when doing the following since conditionals like `and` and `or` are defined with a return type of `SQL | undefined`.
```typescript
await db
.insert(usersTable)
.values({
name: "lanpai",
age: 1,
email: "one@foo.bar",
})
.onConflictDoUpdate({
target: usersTable.id,
set: {
age: 2,
email: "two@foo.bar",
},
setWhere: and( // <- Type 'undefined' is not assignable to type 'SQL'
ne(usersTable.age, sql`excluded.age`),
ne(usersTable.email, sql`excluded.email`),
),
});
```

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.