Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ehahn9 opened this issue Mar 1, 2024 · 0 comments

Comments

@ehahn9
Copy link

ehahn9 commented Mar 1, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant