Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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
   */
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seem to work now,

  /**
   * Handle creating a new course.
   * @async
   * @method
   * @param {{ CourseService  }} requestBody - Request Body
   * @returns {Promise<function(ExpressRequest): Promise.<ControllerResponse>> }
   */
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!