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 types for Object Listener #4338

Merged
merged 1 commit into from
Feb 14, 2022
Merged

Conversation

takameyer
Copy link
Contributor

When a class extends Realm.Object, adding a listener to an instance of the
object would not correctly type the object returned in the callback.
With this change, the callback returns an object of the same type as the
instance it was called from.

This closes #4337

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 🚦 Tests
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

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

@cla-bot cla-bot bot added the cla: yes label Feb 11, 2022
@@ -1,3 +1,4 @@
c76131748cbb048e78a987eb234d8a9609e26430
f38d8cf7cac992767a451d2f3cf3310e3546bf6f
fa80f12bf3fbfe1337ae69e12c59051fac347001
99e64a8e990d2579bcfe382f755edbc61f70af4e
Copy link
Member

Choose a reason for hiding this comment

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

Was this on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes...the types document still had our merge commit from version 10.5.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow that seems to exist across multiple SHAs.

@takameyer takameyer requested a review from tomduncalf February 11, 2022 13:27
@takameyer takameyer force-pushed the andrew/object-listener-type branch 2 times, most recently from bb49df8 to d7cffb9 Compare February 11, 2022 14:29
When a class extends Realm.Object, adding a listener to an instance of the
object would not correctly type the object returned in the callback.
With this change, the callback returns an object of the same type as the
instance it was called from.
@takameyer takameyer force-pushed the andrew/object-listener-type branch from d7cffb9 to 3d26608 Compare February 11, 2022 14:29
@@ -251,16 +251,16 @@ declare namespace Realm {
/**
* @returns void
*/
addListener(callback: ObjectChangeCallback): void;
addListener(callback: ObjectChangeCallback<this>): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice trick ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Game changer.

@takameyer takameyer merged commit 905b1fc into master Feb 14, 2022
@takameyer takameyer deleted the andrew/object-listener-type branch February 14, 2022 11:50
takameyer added a commit that referenced this pull request Feb 14, 2022
When a class extends Realm.Object, adding a listener to an instance of the
object would not correctly type the object returned in the callback.
With this change, the callback returns an object of the same type as the
instance it was called from.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Realm.Object#addListener type signature
3 participants