In the Angular "Tour of Heroes" tutorial, an error handler method is defined which returns a lambda:
private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
this.log(`${operation} failed: ${error.message}`);
return of(result as T);
};
The handleError
method has no return type and is therefore inferred. What would the return type be if we wanted to make it explicit? I've tried Function (lib.es2015.core.d.ts) but that doesn't work.
Adding the lambda itself as a return type works, but seems wrong:
private handleError<T>(operation = 'operation', result?: T): (error: any) => Observable<T> {
return (error: any): Observable<T> => {
...
What is the correct Typescript type for a lambda? In Java, handleError would return a java.util.function.Function. Is there anything similar in Typescript? Thank you.