In the code snippet below, I have a controller that acts as a higher order method:
const CourseController = {
createCourse:
({ CourseService }) =>
async (httpRequest) => {
const course = await CourseService.doCreateCourse(httpRequest.body);
return {
statusCode: 201,
body: {
data: course
}
};
},
}
Here is my type definition for the controller's return type:
/**
* ControllerResponse
* @typedef {Object} ControllerResponse
* @property {Number} statusCode
* @property {{ data: (Object | Array )}} body
*/
I am trying to figure out how to define the type for createCourse
so that it returns the ControllerResponse
type.
Update:
I attempted to define the type using the following code. It seems to work, but the return type from the controller does not appear to be correct. When I mark it as async,
@returns {async function(ExpressRequest): Promise.<ControllerResponse> }
I lose the type definition.
/**
* Handle creating a new course.
* @async
* @method
* @param {{ CourseService }} requestBody - Request Body
* @returns {function(ExpressRequest): Promise.<ControllerResponse> } Course
*/