Why the need to use "result as" in the return of a generic method?

0

Consider the following method:

private handleError<T> (operation = 'operation', result?: T) {
    return (error: any): Observable<T> => {
        this.log('${operation} failed: ${error.message}');
        return of(result as T);
    };
}

Considering that the implementation of a generic type implies a return of the same type of generic T , why the need to use result as T , where result will always be T ? >

return of(result as T);
    
asked by anonymous 27.12.2017 / 15:17

0 answers