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

FIX #6188 Wrong Reactivity generics passed by RxCollection extending … #6189

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading