github TanStack/db @tanstack/db@0.5.17

latest releases: @tanstack/angular-db@0.1.44, @tanstack/rxdb-db-collection@0.1.50, @tanstack/svelte-db@0.1.61...
3 days ago

Patch Changes

  • Export QueryResult helper type for easily extracting query result types (similar to Zod's z.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 ExtractContext for 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.) in where() or having() callbacks instead of query builder functions (eq, gt, etc.), the query builder now throws a helpful InvalidWhereExpressionError with 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 deepEquals when comparing different special types (Date, RegExp, Map, Set, TypedArray, Temporal, Array). Previously, comparing values like deepEquals(Date, Temporal.Duration) could return a different result than deepEquals(Temporal.Duration, Date). Now both directions correctly return false for mismatched types, ensuring deepEquals is a proper equivalence relation. (#1018)

  • Add where callback option to subscribeChanges for 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'),
    })

Don't miss a new db release

NewReleases is sending notifications on new releases.