pubkey/rxdb

Wrong generics passed by RxCollection extending RxCollectionBase

artaommahe opened this issue · 4 comments

RxCollectionBase has 5 generics with Reactivity as a last one. When RxCollection extends RxCollectionBase it passes only 4 of them and instead of passing StaticMethods as 4th the Reactivity is used.

RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, Reactivity> &

export type RxCollection<
    RxDocumentType = any,
    OrmMethods = {},
    StaticMethods = {},
    InstanceCreationOptions = {},
    Reactivity = unknown
> = StaticMethods &
    RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, Reactivity> &
    RxCollectionGenerated<RxDocumentType, OrmMethods, Reactivity>;

export class RxCollectionBase<

export class RxCollectionBase<
    InstanceCreationOptions,
    RxDocumentType = { [prop: string]: any; },
    OrmMethods = {},
    StaticMethods = { [key: string]: any; },
    Reactivity = any
> {

This leads to wrong types for Reactivity and most likely StaticMethods

export interface DbCollections<Reactivity> {
  smth: RxCollection<Smth, unknown, unknown, unknown, Reactivity>;
}

export type Db = RxDatabase<DbCollections<Signal<unknown>>, unknown, unknown, Signal<unknown>>;

let db: Db;

const data = db.smth.find().$$;
//         ^ any

Btw also looks like even after fixing this issue types for reactivity .$$ will be wrong and always equal passed Reactivity generic value (Signal<unknown> in the example above)

Thanks for investigation. PR is welcomed. I tried to fix the Signal problem some time ago but did not find a solution.

Fixed in the linked commit. Please test the next release.

@pubkey the type is better now, thx!

as for proper reactivity types looks like it's not possible with the current typescript and requires smth like this to be implemented microsoft/TypeScript#1213

@artaommahe Thank you for that link. This helps me a lot because I can now stop looking for how to make it work and just wait for that issue to be resolved.