Fix type definitions - generics return <T & Object> (#2110)

* Be explicit that the return type of generic methods will be an intersection with Object
This commit is contained in:
Nikola Irinchev 2018-11-15 11:33:24 +01:00 committed by Kenneth Geisshirt
parent f0fc556f6e
commit 0b14436dc4
2 changed files with 5 additions and 4 deletions

View File

@ -6,6 +6,7 @@ x.x.x Release notes (yyyy-MM-dd)
### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* Removed calls to `new Buffer()` as this is deprecated with Node 10. ([#2107](https://github.com/realm/realm-js/issues/2107), since 2.19.0)
* Updated the type definitions to be explicit that the return type of the generics `Realm.objects<T>`, `Realm.objectForPrimaryKey<T>`, etc. is an intersection of `T & Realm.Object`. ([#1838](https://github.com/realm/realm-js/issues/1838))
### Compatibility
* Realm Object Server: 3.11.0 or later.

8
lib/index.d.ts vendored
View File

@ -118,7 +118,7 @@ declare namespace Realm {
/**
* @returns Results<T>
*/
linkingObjects<T>(objectType: string, property: string): Results<T>;
linkingObjects<T>(objectType: string, property: string): Results<T & Realm.Object>;
/**
* @returns number
@ -701,7 +701,7 @@ declare class Realm {
* @param {Realm.ObjectSchema} object schema describing the object that should be created.
* @returns {T}
*/
static createTemplateObject<T>(objectSchema: Realm.ObjectSchema): T;
static createTemplateObject<T>(objectSchema: Realm.ObjectSchema): T & Realm.Object;
/**
* Delete the Realm file for the given configuration.
@ -753,13 +753,13 @@ declare class Realm {
* @param {number|string} key
* @returns {T | undefined}
*/
objectForPrimaryKey<T>(type: string | Realm.ObjectType | Function, key: number | string): T | undefined;
objectForPrimaryKey<T>(type: string | Realm.ObjectType | Function, key: number | string): T & Realm.Object | undefined;
/**
* @param {string|Realm.ObjectType|Function} type
* @returns Realm
*/
objects<T>(type: string | Realm.ObjectType | Function): Realm.Results<T>;
objects<T>(type: string | Realm.ObjectType | Function): Realm.Results<T & Realm.Object>;
/**
* @param {string} name