(req: Request, res: Response, next: NextFunction) => Promise<Response | void>
In the return
statement provided, there is an absence of the async
keyword (since it returns a Promise already) and the syntax for the function return changes from :
to =>
. However, in most scenarios, including this one, omitting the :
is acceptable as TypeScript can deduce the return type from the return
statement.
function saveHistory(log: String):
(req: Request, res: Response, next: NextFunction) => Promise<Response | void> {
return async (req: Request, res: Response, next: NextFunction): Promise<Response | void> => {
try {
// ...
} catch (e) {
// ...
}
};
}
Playground Link