Skip to content

fix(drizzle-orm): make not() accept SQL | undefined from and()/or()#5517

Open
kszongic wants to merge 1 commit intodrizzle-team:mainfrom
kszongic:fix/not-type-with-and-or
Open

fix(drizzle-orm): make not() accept SQL | undefined from and()/or()#5517
kszongic wants to merge 1 commit intodrizzle-team:mainfrom
kszongic:fix/not-type-with-and-or

Conversation

@kszongic
Copy link

Problem

not() only accepts SQLWrapper, but and() and or() return SQL | undefined. This causes a type error when composing them:

await db.query.users.findMany({
  where: not(and(ilike(users.name, '%asdf%')))
})

Solution

Updated not() to accept SQLWrapper | undefined and return SQL | undefined, consistent with and() and or(). When undefined is passed, it returns undefined (no-op), matching the existing pattern.

Changes

  • drizzle-orm/src/sql/expressions/conditions.ts: Changed not(condition: SQLWrapper): SQL to not(condition: SQLWrapper | undefined): SQL | undefined

Fixes #1818

@kszongic kszongic force-pushed the fix/not-type-with-and-or branch from bafd5e8 to d9455e5 Compare March 21, 2026 16:39
@kszongic kszongic force-pushed the fix/not-type-with-and-or branch from d9455e5 to d823e22 Compare March 23, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: not type doesn't work with and and or

1 participant