Patch Changes
-
Export
QueryResulthelper type for easily extracting query result types (similar to Zod'sz.infer). (#1096)import { Query, QueryResult } from '@tanstack/db' const myQuery = new Query() .from({ users }) .select(({ users }) => ({ name: users.name })) // Extract the result type - clean and simple! type MyQueryResult = QueryResult<typeof myQuery>
Also exports
ExtractContextfor advanced use cases where you need the full context type. -
Add validation for where() and having() expressions to catch JavaScript operator usage (#1082)
When users accidentally use JavaScript's comparison operators (
===,!==,<,>, etc.) inwhere()orhaving()callbacks instead of query builder functions (eq,gt, etc.), the query builder now throws a helpfulInvalidWhereExpressionErrorwith clear guidance.Previously, this mistake would result in a confusing "Unknown expression type: undefined" error at query compilation time. Now users get immediate feedback with an example of the correct syntax:
❌ .where(({ user }) => user.id === 'abc') ✅ .where(({ user }) => eq(user.id, 'abc')) -
Fix asymmetric behavior in
deepEqualswhen comparing different special types (Date, RegExp, Map, Set, TypedArray, Temporal, Array). Previously, comparing values likedeepEquals(Date, Temporal.Duration)could return a different result thandeepEquals(Temporal.Duration, Date). Now both directions correctly returnfalsefor mismatched types, ensuringdeepEqualsis a proper equivalence relation. (#1018) -
Add
wherecallback option tosubscribeChangesfor ergonomic filtering (#943)Instead of manually constructing IR with
PropRef:import { eq, PropRef } from '@tanstack/db' collection.subscribeChanges(callback, { whereExpression: eq(new PropRef(['status']), 'active'), })
You can now use a callback with query builder functions:
import { eq } from '@tanstack/db' collection.subscribeChanges(callback, { where: (row) => eq(row.status, 'active'), })