0

我想做,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) } }
4

0 回答 0