angular - TypeScript: El argumento de tipo '(error: any) => void' no se puede asignar al parámetro de tipo
Código siguiente:
private getJSON(): Observable<any> {
return this.http.get('./reportNav-NEW.json')
.map((res:any)=> res.json())
.catch((error:any) => console.log(error));
}
El error me da:
El argumento de tipo '(error: any) => void' no es asignable al parámetro de tipo '(err: any, caught: Observable) => ObservableInput<{}>'. El tipo 'void' no es asignable al tipo 'ObservableInput<{}>'.
Sucede en el .catch((error:any) => console.log(error));
Respuesta #1
Esto funcionó para mí (gracias a @trevor en los comentarios)
private getJSON(): Observable<any> {
console.log(document.location.href);
return this.http.get('...')
.map((res:any)=> res.json())
.catch((error:any) => {
return Observable.throw(error);
})
}
actualización: Ahora con rxjs 6 tienes que llamar al operador "throwError" desde "rxjs/operators", y usarlo en lugar de "Observable.throw".
