From b9e995eb9b93ee6933835d5555173ba185acb303 Mon Sep 17 00:00:00 2001 From: Marvin Luchs Date: Wed, 29 Apr 2015 10:09:09 +0200 Subject: [PATCH 1/2] ICollectionPromise should extend ng.IPromise with an array of T ICollectionPromise extends ng.IPromise is the equivalent of interface IPromise extends ng.IPromise for arrays of T. Therefore it makes no sense to extend ng.IPromise with just T. Instead it has to be an array of T. The consequence of this bug can be observed when calling Restangular.all('someEntity').getList().then((entities) => {...}) In this case the TypeScript compiler handles entities as SomeEntity, not SomeEntity[]. --- restangular/restangular.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restangular/restangular.d.ts b/restangular/restangular.d.ts index 5a4e87483..7b8480895 100644 --- a/restangular/restangular.d.ts +++ b/restangular/restangular.d.ts @@ -15,7 +15,7 @@ declare module restangular { $object: T; } - interface ICollectionPromise extends ng.IPromise { + interface ICollectionPromise extends ng.IPromise { push(object: any): ICollectionPromise; call(methodName: string, params?: any): ICollectionPromise; get(fieldName: string): ICollectionPromise; From a013599373f97ab70ccc6722d29695a2ff72eac2 Mon Sep 17 00:00:00 2001 From: Marvin Luchs Date: Wed, 29 Apr 2015 13:38:43 +0200 Subject: [PATCH 2/2] Added missing plain() and clone() methods to Restangular's IElement and ICollection restangularizeCollection() [1] and restangularizeElem() [2] are used to create objects that implement IElement and ICollection respectively. Both use restangularizeBase() [3] which adds the clone() and plane() methods. Therefore both IElement and ICollection should both implement clone() and plain(). Additionally I added a generic variant of the already existing plain() method in IElement to both IElement and ICollection. [1] https://github.com/mgonto/restangular/blob/master/src/restangular.js#L982 [2] https://github.com/mgonto/restangular/blob/master/src/restangular.js#L951 [3] https://github.com/mgonto/restangular/blob/master/src/restangular.js#L764 --- restangular/restangular.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/restangular/restangular.d.ts b/restangular/restangular.d.ts index 7b8480895..f2388fc12 100644 --- a/restangular/restangular.d.ts +++ b/restangular/restangular.d.ts @@ -114,6 +114,7 @@ declare module restangular { patch(queryParams?: any, headers?: any): IPromise; clone(): IElement; plain(): any; + plain(): T; withHttpConfig(httpConfig: IRequestConfig): IElement; save(queryParams?: any, headers?: any): IPromise; getRestangularUrl(): string; @@ -130,6 +131,9 @@ declare module restangular { patch(queryParams?: any, headers?: any): IPromise; putElement(idx: any, params: any, headers: any): IPromise; withHttpConfig(httpConfig: IRequestConfig): ICollection; + clone(): ICollection; + plain(): any; + plain(): T[]; getRestangularUrl(): string; } }