I am facing an issue with returning an Observable from the second request. Here is the scenario I am encountering:
commandRequest(action:string, commandData:any):Observable<CashDesckResponse>
{
let command:CashDeskRequest;
//ask my backend for command
this.requestCommandString(action, commandData, "POST")
//this is my response from backend
.map(r=>r.response).subscribe(my_1_response=>{
//then i need to send this response data to other server/action
//to execute it and return this second response as the result of
//this method.
command = new CashDesckRequest(my_1_response);
return this.server.executeCommand(command).map(return_this=>return_this);
});
};
private requestCommandString(action:string, requestData:any,
type:string):Observable<AjaxResponse>{
return Observable.ajax({
body:JSON.stringify(requestData),
method:type,
url:this._apiServerUrl+action
}).map(r=>r);
};
The problem arises when trying to return a value from the inner subscribe function. The compiler throws an error stating: [ts] A function whose declared type is neither 'void' nor 'any' must return a value.