Skip to content

Commit

Permalink
FIX #6188 Wrong Reactivity generics passed by RxCollection extending … (
Browse files Browse the repository at this point in the history
#6189)

* FIX #6188 Wrong Reactivity generics passed by RxCollection extending RxCollectionBase

* FIX lint

* ADD comment
  • Loading branch information
pubkey committed Jul 7, 2024
1 parent 7be271f commit 691d1b5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# RxDB Changelog

<!-- CHANGELOG NEWEST -->
- FIX Wrong Reactivity generics passed by RxCollection extending RxCollectionBase [#6188](https://github.com/pubkey/rxdb/issues/6188)
- IMPROVE performance of ChangeEventBuffer by processing events in bulks.
- IMPROVE performance of DocCache by processing events in bulks.
- IMPROVE performance of ChangeEventBuffer and DocCache by lazily processing tasks.
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/state/rx-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class RxStateBase<T, Reactivity = unknown> {
obs,
this.get(path),
this.collection.database
);
) as any;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/rx-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class RxQueryBase<
this.$,
undefined,
this.collection.database
);
) as any;
}

// stores the changeEvent-number of the last handled change-event
Expand Down
2 changes: 1 addition & 1 deletion src/types/rx-collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type RxCollection<
InstanceCreationOptions = {},
Reactivity = unknown
> = StaticMethods &
RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, Reactivity> &
RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, StaticMethods, Reactivity> &
RxCollectionGenerated<RxDocumentType, OrmMethods, Reactivity>;

export interface RxCollectionGenerated<RxDocumentType = any, OrmMethods = {}, Reactivity = unknown> extends RxLocalDocumentMutation<RxCollection<RxDocumentType, OrmMethods, any, any, Reactivity>> {
Expand Down
24 changes: 23 additions & 1 deletion test/typings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
createBlob
} from '../plugins/core/index.mjs';
import { getRxStorageMemory } from '../plugins/storage-memory/index.mjs';
import { Observable } from 'rxjs';

type DefaultDocType = {
passportId: string;
Expand Down Expand Up @@ -406,6 +405,29 @@ describe('typings.test.ts', function () {
});
});
});
describe('reactivity', () => {
type MyCustomReactivity<T> = Set<T>;
type DocType = {
age: number;
firstName: string;
lastName: string;
passportId: string;
};
/**
* @link https://github.com/pubkey/rxdb/pull/6189
*/
it('#6189 should know the type of the custom reactivity object', () => {
type DbCollections = {
smth: RxCollection<DocType, unknown, unknown, unknown, MyCustomReactivity<unknown>>;
};
type Db = RxDatabase<DbCollections, unknown, unknown, MyCustomReactivity<unknown>>;
const db: Db = {} as any;
const data: MyCustomReactivity<any> = db.smth.find().$$;

// @ts-expect-error should be invalid because MyCustomReactivity is not a number
const dataWrong: number = db.smth.find().$$;
});
});
});
describe('local documents', () => {
it('should allow to type input data', async () => {
Expand Down

0 comments on commit 691d1b5

Please sign in to comment.