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

TypeScript + useRxCollection() + static methods not working? #83

Open
GRardB opened this issue Dec 29, 2023 · 1 comment
Open

TypeScript + useRxCollection() + static methods not working? #83

GRardB opened this issue Dec 29, 2023 · 1 comment

Comments

@GRardB
Copy link

GRardB commented Dec 29, 2023

Hey there!

I've got a collection that looks like this:

type EventCollection = RxCollection<
  EventRecordType,
  Record<string, never>,
  EventCollectionStaticMethods
>;

It has some static methods, but if I call useRxCollection(), there's no good way of TypeScript knowing that. The hook only accepts a single generic which is for the document type (i.e. RxCollection<T>), so I can't provide the types for my static methods.

I think it would make more sense if the generic was for the collection itself, rather than the document type, e.g.:

const events = useRxCollection<EventCollection>("events")

I realize that's a breaking change, though, so perhaps it would be enough for the function to accept all three generic types? That way, I could at least do this:

declare function useRxCollection<A, B, C>(
  name: string,
): RxCollection<A, B, C> | null;

...

const events: EventCollection = useRxCollection("events")

Right now, that line of code fails because the second and third generics aren't being passed through.

I'm happy to open a PR if you want, though I think the change would be very quick.

Thanks!

@jb-delightai
Copy link

+1 similarly, if you define ORM methods on your collection, it doesn't have a way of recognizing that the result documents have those methods available

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

2 participants