Skip to content

fix: allow not() to accept return types of and() and or()#5654

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

fix: allow not() to accept return types of and() and or()#5654
yosofbadr wants to merge 1 commit intodrizzle-team:mainfrom
yosofbadr:fix/not-type-with-and-or

Conversation

@yosofbadr
Copy link
Copy Markdown

@yosofbadr yosofbadr commented Apr 15, 2026

Summary

  • Updated the not() function type signature to accept SQLWrapper | undefined (instead of just SQLWrapper) and return SQL | undefined (instead of just SQL)
  • When undefined is passed (e.g. from and() or or() returning undefined), not() now returns undefined instead of producing a type error
  • This makes not() composable with and() and or() without requiring type assertions

Problem

and() and or() return SQL | undefined, but not() only accepted SQLWrapper. This caused a TypeScript error when composing them:

// Type error: Argument of type 'SQL<unknown> | undefined' is not assignable to parameter of type 'SQLWrapper'.
not(and(ilike(users.name, '%asdf%')))

Fixes #1818

Test plan

  • Verify not(and(...)) compiles without type errors
  • Verify not(or(...)) compiles without type errors
  • Verify not(undefined) returns undefined
  • Verify not(someCondition) still returns SQL as before when given a defined condition
  • Verify existing tests pass

The not() function previously only accepted SQLWrapper, but and() and
or() return SQL | undefined. This caused a type error when composing
not(and(...)) or not(or(...)). Updated not() to accept
SQLWrapper | undefined and return SQL | undefined, returning undefined
when passed undefined for consistency with and() and or().

Fixes drizzle-team#1818
@yosofbadr yosofbadr marked this pull request as ready for review April 15, 2026 20:21
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