drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: stronger conditional typing for `and` and `or` operators

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

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

A trivial change to the type overloading declarations of the `and` and `or` operators used for constructing filters can improve type inference.

See their definitions [here](https://github.com/drizzle-team/drizzle-orm/blob/53f578c11a77c7c086f9c3ed897afdebce7ed6e6/drizzle-orm/src/sql/expressions/conditions.ts#L104-L164).

Note that they return a union `SQL | undefined` to account for the fact that when the list of clauses being provided are empty the operators return `undefined` which plugs into drizzle's [conditional filtering api](https://orm.drizzle.team/docs/guides/conditional-filters-in-query) (as a separate note, I believe that this is not consistent with conventional logical interpretations of empty disjunctions: `undefined` seems to indicate that no filter is being applied, whereas an empty disjunction is conventionally equivalent to falsehood, which might be interpreted as everything being filtered out...). There are circumstances when this type can be determined to be narrower, such as when it is known that the list of clauses is non-empty. I suggest that we overload these operators to account for that.

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.