From b11a64d669a62f86f0d1bfadfab2b17cd70b7501 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:56:18 +0200 Subject: [PATCH 1/3] FIX #6188 Wrong Reactivity generics passed by RxCollection extending RxCollectionBase --- CHANGELOG.md | 1 + src/plugins/state/rx-state.ts | 2 +- src/rx-query.ts | 2 +- src/types/rx-collection.d.ts | 2 +- test/typings.test.ts | 21 ++++++++++++++++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afcbaa36ebc..33a3425ebdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # RxDB Changelog +- 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. diff --git a/src/plugins/state/rx-state.ts b/src/plugins/state/rx-state.ts index 886525e6d58..9e0f7266c50 100644 --- a/src/plugins/state/rx-state.ts +++ b/src/plugins/state/rx-state.ts @@ -197,7 +197,7 @@ export class RxStateBase { obs, this.get(path), this.collection.database - ); + ) as any; } /** diff --git a/src/rx-query.ts b/src/rx-query.ts index 286710af1a5..02bbaa57cf0 100644 --- a/src/rx-query.ts +++ b/src/rx-query.ts @@ -181,7 +181,7 @@ export class RxQueryBase< this.$, undefined, this.collection.database - ); + ) as any; } // stores the changeEvent-number of the last handled change-event diff --git a/src/types/rx-collection.d.ts b/src/types/rx-collection.d.ts index c5b3cf90adc..2ba67051f6d 100644 --- a/src/types/rx-collection.d.ts +++ b/src/types/rx-collection.d.ts @@ -80,7 +80,7 @@ export type RxCollection< InstanceCreationOptions = {}, Reactivity = unknown > = StaticMethods & - RxCollectionBase & + RxCollectionBase & RxCollectionGenerated; export interface RxCollectionGenerated extends RxLocalDocumentMutation> { diff --git a/test/typings.test.ts b/test/typings.test.ts index 4fc2e387247..8f38b75ae4a 100644 --- a/test/typings.test.ts +++ b/test/typings.test.ts @@ -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; @@ -406,6 +405,26 @@ describe('typings.test.ts', function () { }); }); }); + describe('reactivity', () => { + type MyCustomReactivity = Set; + type DocType = { + age: number; + firstName: string; + lastName: string; + passportId: string; + }; + it('should know the type of the custom reactivity object', async () => { + type DbCollections = { + smth: RxCollection>; + } + type Db = RxDatabase>; + let db: Db = {} as any; + const data: MyCustomReactivity = 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 () => { From 012e66b707ea92fee064186a8500d192f084b7e1 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:11:19 +0200 Subject: [PATCH 2/3] FIX lint --- test/typings.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/typings.test.ts b/test/typings.test.ts index 8f38b75ae4a..0673973ff82 100644 --- a/test/typings.test.ts +++ b/test/typings.test.ts @@ -413,12 +413,12 @@ describe('typings.test.ts', function () { lastName: string; passportId: string; }; - it('should know the type of the custom reactivity object', async () => { + it('should know the type of the custom reactivity object', () => { type DbCollections = { smth: RxCollection>; - } + }; type Db = RxDatabase>; - let db: Db = {} as any; + const db: Db = {} as any; const data: MyCustomReactivity = db.smth.find().$$; // @ts-expect-error should be invalid because MyCustomReactivity is not a number From 20ef898eb5eb07255ee8a07184903e72b6927878 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Sun, 7 Jul 2024 23:02:02 +0200 Subject: [PATCH 3/3] ADD comment --- test/typings.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/typings.test.ts b/test/typings.test.ts index 0673973ff82..8399487221b 100644 --- a/test/typings.test.ts +++ b/test/typings.test.ts @@ -413,7 +413,10 @@ describe('typings.test.ts', function () { lastName: string; passportId: string; }; - it('should know the type of the custom reactivity object', () => { + /** + * @link https://github.com/pubkey/rxdb/pull/6189 + */ + it('#6189 should know the type of the custom reactivity object', () => { type DbCollections = { smth: RxCollection>; };