Closed
Description
When a collection is created with .findOne(), it's typed as Collection<T> & SingleResult, correctly indicating it returns at most one row. However, when this collection is passed to queryOnce, the SingleResult information is lost:
// Collection correctly typed as SingleResult
const collection = createLiveQueryCollection({
query: (q) => q.from({ users }).where(...).findOne(),
}); // Collection<User> & SingleResult
// queryOnce wraps it in q.from(), losing SingleResult - returns User[] instead of User | undefined
const result = await queryOnce((q) => q.from({ user: collection }));
// ^? User[] — have to destructure: const [user] = resultExpected behavior:
queryOnce should either:
- Accept a
SingleResultcollection directly and returnPromise<T | undefined>, or - Preserve the
SingleResultmarker throughq.from()soInferResultTypereturnsT | undefinedinstead ofT[]
Current workaround:
const [result] = await queryOnce((q) =>
q.from({ config: singleResultCollection }),
);This works but loses type safety - result is typed as T | undefined only because of array destructuring, not because the type system knows it's a single-result query.
Metadata
Metadata
Assignees
Labels
No labels
Activity
KyleAMathews commentedon Sep 17, 2026
Closing this for the pre-1.0 cleanup. The reported typing gap is real, but fixing it requires choosing whether SingleResult cardinality belongs to the source collection, a queryOnce overload, or the composed query graph across joins and unions. The current array-destructuring workaround remains safe. We can reopen with renewed demand once we are ready to define that cardinality contract.