TanStack / TanStack/db

Should AND and OR operators support 0 or more arguments (instead of 2 or more)

Open
#506 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

It makes sense to turn the and and or operators into vararg functions. That would simplify their usage, as shown by this code snippet from this issue:

let conditions = [];
for (const key of filters) {
  conditions.push(eq(product.id, key));
}
return or(...conditions);

This is currently not possible because or expects exactly two arguments. This should be the behavior of or:

  • if 0 arguments provided: evaluates to true
  • if 1 predicate provided: returns that predicate
  • if 2 predicates provided: ors them together
  • if 3 or more predicates provided: nested ors

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names the TypeScript and and or operators but no files or tests. First locate their definitions and existing operator tests, then verify the requested zero-, one-, two-, and three-plus-predicate cases; clarify the corresponding behavior for and before treating the work as complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.