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 (v6) #3271

Merged
merged 9 commits into from
Oct 2, 2020

Conversation

steffenagger
Copy link
Contributor

@steffenagger steffenagger commented Sep 28, 2020

Main goal

Initiated based on this comment: #3044 (comment) - v10 PR can be found here: #3266.

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

create<T> 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;

Additional changes

objectForPrimaryKey<T> updated to:

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

/** ... */
objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: number | string): 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).

I extended integration-tests for object creation/reading to include update-tests, a objectForPrimaryKey test & include Class Models in testing (these additions only works in combination with the merged #3261).

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)).

☑️ 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 marked this pull request as ready for review September 28, 2020 13:59
@steffenagger steffenagger self-assigned this Sep 28, 2020
Copy link
Member

@kraenhansen kraenhansen left a comment

Choose a reason for hiding this comment

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

Looking good :)

@steffenagger steffenagger merged commit bae3827 into master Oct 2, 2020
@steffenagger steffenagger deleted the sa/fix-ts-create-declarations branch October 2, 2020 11:30
@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.

4 participants