Describe the bug
UseLiveQueryReturn when used agains a ElectricCollection, doesn't match what actually a useLiveQuery returns for a query from an electric collection.
To Reproduce
Steps to reproduce the behavior:
- Create zod schema
import { z } from 'zod/v4';
export const actionSchema = z.object({
id: z.string().uuid(),
label: z.string(),
// ... wathever...
});
export type Action = z.infer<typeof actionSchema>;
- Create a collection
const electricOpts = electricCollectionOptions({
id: 'actions',
schema: actionSchema,
getKey: (item) => item.id,
shapeOptions: {
url: `${env.PUBLIC_URL}/shapes/actions`,
subsetMethod: 'POST',
columnMapper: snakeCamelMapper(),
},
});
export const actionsCollection = createCollection(electricOpts);
- Query it using live query (in svelte in this case, and inside of a class)
#query: UseElectricLiveQueryReturn<Action> | null = $state(null);
// ...class stuff...
this.#query = useLiveQuery((q) =>
q.from({ a: actionsCollection }).orderBy(({ a }) => a.createdAt, 'desc').limit(50),
);
- Expect a type error that the query is missing
{ readonly $synced: boolean; readonly $origin: VirtualOrigin; readonly $key: string | number; readonly $collectionId: string; } from the original type passed (Action in this case)
Expected behavior
Type should match correctly when inferring from UseElectricLiveQueryReturn<Action>
Workaround
I've created the follow type util to help me while this is an issue
import type { UseLiveQueryReturn, VirtualOrigin } from "@tanstack/svelte-db";
export type UseElectricLiveQueryReturn<T extends object> = UseLiveQueryReturn<T & {
readonly $synced: boolean; readonly $origin: VirtualOrigin; readonly $key: string | number; readonly $collectionId: string;
}>;
Describe the bug
UseLiveQueryReturnwhen used agains a ElectricCollection, doesn't match what actually auseLiveQueryreturns for a query from an electric collection.To Reproduce
Steps to reproduce the behavior:
{ readonly $synced: boolean; readonly $origin: VirtualOrigin; readonly $key: string | number; readonly $collectionId: string; }from the original type passed (Actionin this case)Expected behavior
Type should match correctly when inferring from
UseElectricLiveQueryReturn<Action>Workaround
I've created the follow type util to help me while this is an issue