Skip to content

Electric collection utils are not typed in mutation functions #792

@godiagonal

Description

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

Describe the bug
The collection.utils received in onInsert, onUpdate and onDelete of electricCollectionOptions is typed as UtilsRecord rather than ElectricCollectionUtils<T>. This makes it unsafe to call awaitTxId and awaitMatch.

To Reproduce

const todosCollection = createCollection(
  electricCollectionOptions({
    id: 'todos',
    getKey: (item) => item.id,
    shapeOptions: {
      url: '/api/todos',
      params: { table: 'todos' },
    },
    onInsert: async ({ collection }) => {
      // ❌ This is typed as UtilsRecord instead of ElectricCollectionUtils<T>
      collection.utils;
    },
  }),
);

// ✅ This is typed as ElectricCollectionUtils<T>
todosCollection.utils;

Expected behavior
I expect mutation functions in electricCollectionOptions to receive collection utils typed as ElectricCollectionUtils<T>.

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