drizzle-team / drizzle-team/drizzle-orm
[BUG]: some filter definitions could use the addition of the `undefined` type
- 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
Assessment
This issue has not been assessed yet.