'Define type for higher order function

I have below controller which is a higher order method,

const CourseController = {
  createCourse:
    ({ CourseService }) =>
    async (httpRequest) => {
      const course = await CourseService.doCreateCourse(httpRequest.body);
      return {
        statusCode: 201,
        body: {
          data: course
        }
      };
    },
}

Below is my type definition for controller return type.

/**
 * ControllerResponse
 * @typedef {Object} ControllerResponse
 * @property {Number} statusCode
 * @property {{ data: (Object | Array )}} body
 */

How do I define type for createCourse so that It returns ControllerResponse type?

Update:

Tried something like below. It works, but return type from the controller doesn't seem right. When I mark it async,

@returns {async function(ExpressRequest): Promise.<ControllerResponse> }

I loose the type definition.

  /**
   * Handle creating a new course.
   * @async
   * @method
   * @param {{ CourseService  }} requestBody - Request Body
   * @returns {function(ExpressRequest): Promise.<ControllerResponse> } Course
   */


Solution 1:[1]

It seem to work now,

  /**
   * Handle creating a new course.
   * @async
   * @method
   * @param {{ CourseService  }} requestBody - Request Body
   * @returns {Promise<function(ExpressRequest): Promise.<ControllerResponse>> }
   */

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 confusedWarrior