-
Notifications
You must be signed in to change notification settings - Fork 191
Open
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels