I'm new of Angular2/Typescript, I'm trying to compile my project but I get this error:
A function whose declared type is neither 'void' nor 'any' must return a value
This is the code:
SyncCustomer(codCli: string): Observable<any>
{
this.mdService.Ordini_Sincronizza(codCli).subscribe(
data => {
return Observable.of(data);
},
error => {
console.log(error);
return Observable.of(error);
});
}
I don't realize where the problem is...
Thanks to support!
UPDATE 001:
I edited the code in this way and now it compiles...
SyncCustomer(codCli: string): Observable<any> {
return Observable.of(this.mdService.Ordini_Sincronizza(codCli).subscribe(
data => {
return data;
},
error => {
console.log(error);
return error;
}));
}
Does it have sense to return an observable of the subscribe ???
return
in front of the first line:return this.mdService.Ordini_Sincronizza
... – Faisalvoid
orany
then the method must return a value i.e. you must use thereturn
keyword in the method. – codejockie