diff --git a/imports/api/makeObservedQueryPublication.ts b/imports/api/makeObservedQueryPublication.ts index 5ada6686c..acffca448 100644 --- a/imports/api/makeObservedQueryPublication.ts +++ b/imports/api/makeObservedQueryPublication.ts @@ -66,24 +66,23 @@ const makeObservedQueryPublication = ( const diffOptions = callbacks.changed ? undefined : { - projectionFn: ({_id}) => _id, + // @ts-expect-error TODO + projectionFn: ({_id}: T): Partial => ({_id}), }; - const observer: ObserveChangesCallbacks = Object.fromEntries( - [ - callbacks.addedBefore && ['addedBefore', stop], - callbacks.movedBefore && ['movedBefore', stop], - callbacks.removed && ['removed', stop], - callbacks.changed && ['changed', stop], - ].filter(Boolean), - ); + const observer: ObserveChangesCallbacks = {}; + + if (callbacks.addedBefore) observer.addedBefore = stop; + if (callbacks.movedBefore) observer.movedBefore = stop; + if (callbacks.removed) observer.removed = stop; + if (callbacks.changed) observer.changed = stop; const handle = await watch( QueriedCollection, selector as Filter, options, async (init) => { - DiffSequence.diffQueryOrderedChanges( + DiffSequence.diffQueryOrderedChanges( handle.init, init, observer, diff --git a/types/meteor/diff-sequence.d.ts b/types/meteor/diff-sequence.d.ts index 64bd3d928..90631e920 100644 --- a/types/meteor/diff-sequence.d.ts +++ b/types/meteor/diff-sequence.d.ts @@ -8,8 +8,8 @@ declare module 'meteor/diff-sequence' { namespace DiffSequence { function diffQueryOrderedChanges( - old_results: T, - new_results: T, + old_results: T[], + new_results: T[], observer: Mongo.ObserveChangesCallbacks, options?: Options | undefined, ): void;