I recently encountered this issue after updating to TS 2.2.2, and I suspect that is the root cause... While the code still functions properly, I am now seeing this error. I attempted various solutions such as returning an empty observable, catching the re-thrown exception, and returning an object, but nothing seemed to resolve it. Why is this problem arising now? Shouldn't it recognize I am re-throwing the exception and not expect a return? Could I be misinterpreting the error message?
Here is the detailed description of the error:
https://i.sstatic.net/ePmFC.jpg
Below is the complete code snippet:
return request
.map((res: Response) => res.json())
.catch((error: any) => {
// todo: log?
if (error.status == 500) {
this.alertService.showError(error.statusText);
} else if (error.status == 588) {
this.alertService.showAlert(error.statusText);
}
Observable.throw(error.statusText);
});
I attempted to return the Observable, however, my wrapper method requires a return type T
, which corresponds to the deserialized request's return value from map(...)
. If I do include the throw
, I receive the following error message:
[ts] Type 'Observable' is not assignable to type 'T'
The technologies I am using are:
- Angular4
- Typescript 2.2.2