定义高阶函数的类型



下面的控制器是一个高阶方法,

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

下面是我对控制器返回类型的类型定义。

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

我如何为createCourse定义类型,使它返回ControllerResponse类型?

更新:

尝试如下。它工作,但从控制器返回类型似乎不正确。当我把它标记为async时,

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

我丢失了类型定义

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

现在好像起作用了,

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

最新更新