Skip to content
Source
Sign inSign up
TanStack/db

fix(db): use Ref<T, Nullable> for left join select refs instead of Ref<T> | undefined #1262

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/1262/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 6 changed files with 44 additions and 37 deletions (loading 4).

x
0 of 6 viewed, 6 left
7 additions and 0 deletions.changeset/fix-nullable-join-select-ref-typing.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/db': patch
+---
+​
+fix(db): use `Ref<T, Nullable>` brand instead of `Ref<T> | undefined` for nullable join refs in declarative select
+​
+The declarative `select()` callback receives proxy objects that record property accesses. These proxies are always truthy at build time, but nullable join sides (left/right/full) were typed as `Ref<T> | undefined`, misleading users into using `?.` and `??` operators that have no effect at runtime. Nullable join refs are now typed as `Ref<T, true>`, which allows direct property access without optional chaining while correctly producing `T | undefined` in the result type.
37 additions and 37 deletionspackages/db-collection-e2e/src/suites/joins.suite.tsModified
View file
@@ -24,9 +24,9 @@
eq(user.id, post.userId),
.select(({ user, post }) => ({
- id: post!.id,
+ id: post.id,
userName: user.name,
- postTitle: post!.title,
+ postTitle: post.title,
})),
​
@@ -53,12 +53,12 @@