Abazhenov / express-async-handler

Async Error Handling Middleware for Express
572 stars 39 forks source link

Wrong type definition for Typescript #39

Open Binero opened 3 years ago

Binero commented 3 years ago

The Typescript function is defined to take an express.RequestHandler which returns void. This ironically means it cannot take an async function as an argument, as this would return Promise<void>.

https://github.com/Abazhenov/express-async-handler/blob/master/index.d.ts#L3

salolivares commented 3 years ago

This issue is made visible with the following eslint rule enabled: https://github.com/typescript-eslint/typescript-eslint/blob/v4.2.0/packages/eslint-plugin/docs/rules/no-misused-promises.md

The following code lights up as a warning due to the rule:

const getList = asyncHandler(
  async (req: Request, res: Response): Promise<void> => {
    // async code
  },
);
JohnXLivingston commented 3 years ago

I have the same issue. It seems that there is a PR for that: https://github.com/Abazhenov/express-async-handler/pull/40 Can you merge it please?