Skip to content

Conversation

@dherges
Copy link
Contributor

@dherges dherges commented Feb 16, 2019

No description provided.

@dherges dherges marked this pull request as ready for review February 18, 2019 06:25
* constructor(private api: ApiClient)
*
* fetchNextPage(res: Respurce<Entity>) {
* return this.api.call(res).get('next').send<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weak link in the Call api. From <R>send(), you always get a Call<R> with a Resource<R>. What about Call<R, D> to get a R extends Resource<D>?

I think we need:

  • call() w/o generics to get an any-typed Resource<any>
  • <R>call() w/ generic type to get an R extends Resource<?>

Thus, the Call<R extends Resource<?>> call class would work with Resource....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export class Call2<R> {

  constructor(
    public resource: R & ResourceMetadata
  ) {}

  // PROBLEM: only one of the method declaration overrides seems to work...
  //public next(): Call2<ResourceMetadata>;
  public next<NextResource>(): Call2<NextResource> {
    return new Call2(this.resource);
  }

}

interface FooRes extends Resource {
  bar: string;  
}

const resource1: Resource = {};
const call2 = new Call2({}); // <-- good, compile error

call2.resource._links; // <-- good, type ResourceMetadata found

const next1 = call2.next();
const next2 = call2.next<FooRes>();

next1.resource._links.self; // <-- bad, type ResourceMetadata not recognized
next2.resource._links.self; // <-- good
next2.resource.bar; // <-- good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In typescript playground, it's supposed to work in TypeScript 3.3

* @return Embedded resource or an `undefined` value
* @stable
*/
export function embedded<T>(rel: string, res: any, opts?: EmbeddedOpts<T>): Resource<T> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
export function embeddeds<T>(rel: string, res: any, opts?: EmbeddedOpts<T>): Resource<T>[] {
if (hasEmbedded(res)) {
const em = res._embedded[rel];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants