我想做,catchAsync1
但收到错误
“void”类型上不存在属性“catch”
并且想知道catchAsync3
并且catchAsync2
在打字稿中是正确的
import { NextFunction, Request, RequestHandler, Response } from 'express'
export const catchAsync1 = (handler: RequestHandler) =>
(...args: [Request, Response, NextFunction]) => handler(...args).catch(args[2])
export const catchAsync2 = (handler: RequestHandler) =>
(req: Request, res: Response, next: NextFunction) => { try { handler(req, res, next) } catch (err) { next(err) } }
export const catchAsync3 = (handler: RequestHandler) =>
(...args: [Request, Response, NextFunction]) => { try { handler(...args) } catch (err) { args[2](err) } }