1

I would like to do catchAsync1 but getting Error

Property 'catch' does not exist on type 'void'

and would like to know catchAsync3 and catchAsync2 are correct in typescript

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) } }
noiissyboy
  • 61
  • 2
  • 5

0 Answers0