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 for TS create declarations when updating (v10) #3266

Merged
merged 7 commits into from
Sep 30, 2020

Conversation

steffenagger
Copy link
Contributor

@steffenagger steffenagger commented Sep 25, 2020

Main goal

Initiated based on this comment: #3044 (comment) - v6 PR can be found here: #3271

Allow for partial models when using Realm.UpdateMode.All or Realm.UpdateMode.Modified

Create declarations has been updated to:

/** ... */
create<T>(type: string, properties: RealmInsertionModel<T>, mode?: Realm.UpdateMode.Never): T & Realm.Object;
create<T>(type: string, properties: Partial<T> | Partial<RealmInsertionModel<T>>, mode: Realm.UpdateMode.All | Realm.UpdateMode.Modified): T & Realm.Object;

/** ... */
create<T extends Realm.Object>(type: {new(...arg: any[]): T; }, properties: RealmInsertionModel<T>, mode?: Realm.UpdateMode.Never): T;
create<T extends Realm.Object>(type: {new(...arg: any[]): T; }, properties: Partial<T> | Partial<RealmInsertionModel<T>>, mode: Realm.UpdateMode.All | Realm.UpdateMode.Modified): T;

Deprecated declarations has been removed after agreement with @kneth
Any better way of achieving the above?

Additional changes

I extended integration-tests for object creation/reading to include update-tests & test for Class Models (these additions only works in combination with #3262 - now rebased on v10 efter merge).

And fixed an issue with serialization tests (so it now works in different environments - the previous error message check was a bit too specific, as described here (MDN)).

Update

objectForPrimaryKey updated to:
(to align with the existing declarations for objects<T>(...) - tests for this added)

/** ... */
objectForPrimaryKey<T>(type: string, key: number | string | Realm.ObjectId): (T & Realm.Object) | undefined;

/** ... */
objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: number | string | Realm.ObjectId): T | undefined;

The above change limits the use of realm.objectForPrimaryKey(Person) to only accept Class Model which extends Realm.Object (just like objects<T>(...) is currently declared).

☑️ ToDos

  • 📝 Changelog entry
  • 🚦 Tests

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated
  • Chrome debug API is updated if API is available on React Native

@steffenagger steffenagger force-pushed the sa/v10/fix-ts-create-declarations branch from f4be753 to b7068de Compare September 28, 2020 07:09
@steffenagger steffenagger changed the title Fix for TS create declarations when updating Fix for TS create declarations when updating (v10) Sep 28, 2020
Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can improve a bit

@steffenagger steffenagger merged commit 555d4a9 into v10 Sep 30, 2020
@steffenagger steffenagger deleted the sa/v10/fix-ts-create-declarations branch September 30, 2020 15:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants