One of the services I provide includes a method with the following implementation:
public fetchCrawls(page: number): Observable<ICrawl[]>{
return this._http.get(this._crawlsURL + page)
.map((res: Response) => {
return {
crawls: <ICrawl[]>res.json(),
headers: res.headers
}
})
.catch(this.handleError);
}
I chose to implement it this way instead
.map((res: Response) => <ICrawl[]>res.json())
This allows me in the consumer component to utilize the headers for pagination:
fetchCrawls(page: number): void {
this._crawlsService.fetchCrawls(page)
.subscribe(
res => {
this.crawls = res.crawls;
this.totalItems = res.headers.get('X-Records');
},
error => this.errorMessage = <any>error);
}
Although it functions correctly, both res.crawls
and res.headers
show as unresolved variables in WebStorm (red), yet the code still compiles without issues.
https://i.sstatic.net/3sRLP.png
This leads me to believe my current approach may be incorrect. How can I avoid having unresolved variables in this scenario?