2
    /** Create curried handleError function that already knows the service name */
      createHandleError = (serviceName = '') =><T>
        (operation = 'operation', result = {} as T) => this.handleError(serviceName, operation, result);

I did not understand the section

=><T> (operation = 'operation', result = {} as T)
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56

2 Answers2

4

createHandleError is a function that returns a generic function.

(serviceName = '') => /* body here */ is the signature of the first function, which returns a second function which happens to be a generic function

<T>(operation = 'operation', result = {} as T) => /* body here */

The <T> is the generic parameter list, followed by the function argument list, which contains 2 arguments, both of which have default values (operation = 'operation' and result = {} as T)

Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
0

Here, what you have is a curried function written using the relatively newer arrow function syntax. In short what a curried function does is, it returns another function when called.

The name of curried function is createHandleError, which accepts a single parameter named serviceName. The parameter (serviceName) has a default value set to it as (serviceName = ''). An empty string '' is the default value of service name.

So, calling createHandleError will return an another function which will accept two parameters namely operation and result (these also have default value allocated to it) and is to show generic parameter list (Just a type). And then it calls handleError function and passes all three parameters to it ie (serviceName, operation, result).

You can call createHandleError like this:

let intermediateCreateHandleErrorFunction = createHandleError("nameOfTheService");
intermediateCreateHandleErrorFunction(someOperation, someResult);                   

Also, you can call createHandleError like this:

createHandleError("nameOfTheService")(someOperation, someResult);
BlackBeard
  • 10,246
  • 7
  • 52
  • 62