Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Example of constructing responses in HTTP method interceptors + typings problem #243

Open
arturhun opened this issue Aug 14, 2019 · 4 comments

Comments

@arturhun
Copy link

Please provide a simple example of constructing a valid response in a method interceptor.

The ticket #44 refers to something that apparently has been moved, and the example in the README is very general, succinct and I find it not helpful at all.

@arturhun
Copy link
Author

arturhun commented Aug 14, 2019

By looking into interfaces.d.ts I managed to come up with something like:

delete(reqInfo: RequestInfo) {
  reqInfo.utils.createResponse$(() => {
    return of({
      collection: collection.filter(item => !deleteSet.has(item.id)),
    });
  });
}

Functionally, this seems to work, however:

  • I assume one would also need to clone the reqInfo parameter to get all the headers, and other props
  • TS complains about the .utils type which allegedly doesn't exist on type RequestInfo, it doesn't exist on type string.

We have type RequestInfo = Request | string;

but (reqInfo as Request).utils. still leaves the squiggles underneath utils.

The above shows that the docs leave much of guesswork for a developer and it could be avoided by provided a decent example.

@vishal423
Copy link
Contributor

did you check under this directory for examples? https://github.com/angular/in-memory-web-api/tree/master/src/app

@arturhun arturhun changed the title Example of constructing responses in HTTP method interceptors Example of constructing responses in HTTP method interceptors + typings problem Aug 14, 2019
@arturhun
Copy link
Author

OK, the typing problem came from that I didn't have an explicit import from the library and so TypeScript used RequestInfo from lib.dom.d.ts

@arturhun
Copy link
Author

@vishal423 Yes I did. and the code that I used based on that

return of({
    items: collection.filter(item => !deleteSet.has(item.id)),  // my collection is `items`
});

didn't work.

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

No branches or pull requests

2 participants