fastify/fastify-http-proxy

Missing type declaration for added hooks in WebSocket connection.

DonVietnam opened this issue · 2 comments

Plugin version

11.1.1

Description

I really appreciate the addition of hook support for WebSocket connections, but at the moment it is not possible to integrate them into an application that is checked with typescript without disabling this check, as the type declaration file for the plugin options has not been updated.

No overload matches this call.
Overload 1 of 3, '(plugin: FastifyPluginCallback<FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled), RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Object literal may only specify known properties, and 'wsHooks' does not exist in type '(RegisterOptions & FastifyHttpProxyOptions & FastifyHttpProxyWebsocketOptionsEnabled) | (RegisterOptions & ... 1 more ... & FastifyHttpProxyWebsocketOptionsDisabled)'.
Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled), RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof fastifyHttpProxy' is not assignable to parameter of type 'FastifyPluginAsync<FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled), RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>'.
Target signature provides too few arguments. Expected 3 or more, but got 2.
Overload 3 of 3, '(plugin: FastifyPluginCallback<FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled), RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Object literal may only specify known properties, and 'wsHooks' does not exist in type '(RegisterOptions & FastifyHttpProxyOptions & FastifyHttpProxyWebsocketOptionsEnabled) | (RegisterOptions & ... 1 more ... & FastifyHttpProxyWebsocketOptionsDisabled)'.ts(2769)

Expected Behavior

Type checking should pass without errors, the type declaration file should be supplemented with the types of new hooks and their parameters.

Also in the documentation in the README for the onConnect method there is no context in the parameters.

Thanks for reporting @DonVietnam!

I'm fixing 🛠