sveltefire icon indicating copy to clipboard operation
sveltefire copied to clipboard

CollectionStore is perhaps typed incorrectly, cannot make any derived stores from them

Open ehahn9 opened this issue 1 year ago • 0 comments

I believe perhaps CollectionStore (and DocStore?) has the wrong unsubscriber type...

import { getFirestore } from 'firebase/firestore';
import { derived } from 'svelte/store';
import { collectionStore } from 'sveltefire';

interface Post {
  id: string;
  title: string;
  body: string;
}

const posts = collectionStore<Post>(getFirestore(), 'posts');
const postsCount = derived(posts, $posts => $posts.length);
//                         ^^^^^

// But with the cast, all is well...
const postsCount2 = derived(posts as Readable<Post[]>, $posts => $posts.length);

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'CollectionStore<Post[]>' is not assignable to parameter of type 'Stores'.
      Type 'CollectionStore<Post[]>' is not assignable to type 'Readable<any>'.
        The types returned by 'subscribe(...)' are incompatible between these types.
          Type 'void | (() => void)' is not assignable to type 'Unsubscriber'.
            Type 'void' is not assignable to type 'Unsubscriber'.  ts(2769)

ehahn9 avatar Mar 01 '24 01:03 ehahn9