Skip to content

Commit

Permalink
Combine type definitions
Browse files Browse the repository at this point in the history
In order to wrap objects and objectForPrimaryKey in Realm React,
it is necessary to combine the overloaded definitions to cleanly
forward the correct typing.
  • Loading branch information
takameyer committed Nov 8, 2021
1 parent d767d91 commit 03b1bb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ x.x.x Release notes (yyyy-MM-dd)
### Internal
* Adding use of [ccache](https://ccache.dev/) in build scripts, XCode projects and the integration tests GHA workflow.
* Dropped using `install-local` in the integration tests, in favour of a more involved Metro configuration.
* Add combined type definition for Realm.object and Realm.objectForPrimaryKey so they can be cleanly wrapped.
* <Either mention core version or upgrade>
* <Using Realm Core vX.Y.Z>
* <Upgraded Realm Core from vX.Y.Z to vA.B.C>
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ declare class Realm {
* @returns {T | undefined}
*/
objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: Realm.PrimaryKey): T | undefined;

// Combined definitions
objectForPrimaryKey<T>(type: string | {new(...arg: any[]): T; }, key: Realm.PrimaryKey): (T & Realm.Object) | undefined;

/**
* @param {string} type
Expand All @@ -761,6 +764,9 @@ declare class Realm {
*/
objects<T extends Realm.Object>(type: {new(...arg: any[]): T; }): Realm.Results<T>;

// Combined definitions
objects<T>(type: string | {new(...arg: any[]): T; }): Realm.Results<T & Realm.Object>;

/**
* @param {string} name
* @param {()=>void} callback
Expand Down

0 comments on commit 03b1bb5

Please sign in to comment.