Skip to content

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

@ehahn9

Description

@ehahn9

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions