2muchcoffeecom / ngx-restangular

Restangular for Angular 2 and higher versions
https://2muchcoffee.com/ngxrestangular-app-development
MIT License
781 stars 110 forks source link

Generics implementation to return object #163

Closed victorsosa closed 5 years ago

victorsosa commented 5 years ago

Hi,

I was thinking that we are missing in this API the Typescript Generics for the function that return the result object.

get<T>([queryParams, headers]):<T>
getList<T>(subElement, [queryParams, headers]):<T>

One example use will be: let clients = this.restangular.all("client").getList<Client>();

This will return a list of objects type Client class; including the rectangular method on it. There is a condition that the Client class has to extent the Restangular class before made any call.

export class Client extends Restangular(){}

because get and getList are implemented in the Restangular class.

Other methods need to be changed to generics like:

This will be a nice feature to be implemented as Typescript use classes.

rshchpkn commented 5 years ago

Hi @victorsosa, unfortunately in current restangular stage I can't find a solution to add correctly typed structure. In general, it's related to the configurable property names. If you have any ideas how it can be performed I will be happy to discuss. PR's are always welcome