Skip to content

UseLiveQueryReturn is missing fields that electric appends #1676

Description

@polvallverdu
  • I've validated the bug against the latest version of DB packages

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:

  1. 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>;
  1. 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);
  1. 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),
);
  1. 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;
	}>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions