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

Generics implementation to return object #163

Closed
victorsosa opened this issue Feb 5, 2019 · 1 comment
Closed

Generics implementation to return object #163

victorsosa opened this issue Feb 5, 2019 · 1 comment

Comments

@victorsosa
Copy link

victorsosa commented Feb 5, 2019

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:

  • put([queryParams, headers]): Does a put to the current element
  • post(subElement, elementToPost, [queryParams, headers]): Does a POST and creates a subElement. Subelement is mandatory and is the nested resource. Element to post is the object to post to the server
  • remove([queryParams, headers]): Does a DELETE. By default, remove sends a request with an empty object, which may cause problems with some servers or browsers. This shows how to configure RESTangular to have no payload.
  • head([queryParams, headers]): Does a HEAD
  • trace([queryParams, headers]): Does a TRACE
  • options([queryParams, headers]): Does a OPTIONS
  • patch(object, [queryParams, headers]): Does a PATCH
  • save()

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

@rshchpkn
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants