fastify/fastify-http-proxy

`preHandler` option is incorrectly typed

Ethan-Arrowood opened this issue · 6 comments

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.21.0

Plugin version

9.2.1

Node.js version

20.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

NA

Description

The type for the preHandler (and assumingly the beforeHandler) options are slightly incorrect as they do not correctly infer support for async:

await app.register(import('fastify-http-proxy'), {
  preHandler: async (request, reply) { },
  ...
};

TypeScript doesn't fail because I believe the current type satisfies the async version, but when you have ESLint enabled, ESLint complains that you are returning a promise where void is expected.

We need to use the preHandlerAsyncHookHandler i think. I'll send a fix soon.

Steps to Reproduce

na

Expected Behavior

na

Maybe has to be typed like I did in the changes in hooks.d.ts (unreleased afaik)

Probably. Is that something unreleased for this module? Or somewhere else?

Ahh so if that is published, then the existing type will work?

I guess after this module is updated to the new version of Fastify too

@Ethan-Arrowood this should be done now