Skip to content

fix(types): type handler as websocket handler in route() with websocket: true - #382

Merged
ilteoood merged 1 commit into
mainfrom
fix/route-websocket-handler-types
Oct 3, 2026
Merged

ilteoood merged 1 commit into
mainfrom
fix/route-websocket-handler-types

Conversation

@Tony133

@Tony133 Tony133 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Proposal:

When using the full declaration syntax with websocket: true, handler is the websocket handler at runtime, but it was typed as a regular HTTP handler, so socket was inferred as FastifyRequest and request as FastifyReply. The shorthand methods already had a websocket: true overload; route() did not.

This adds the equivalent overload for route(), typing handler as WebsocketHandler when websocket: true, including generics and type provider inference.

Note:

  • It is backwards compatible: routes with explicitly annotated HTTP handlers or with a wsHandler alongside websocket: true still compile as before. Rejecting wsHandler when websocket: true (it is ignored at runtime) could be a follow-up, but would be a breaking change for types.
  • Added type tests for the new overload, with explicit generics and with TypeBox inference, plus a websocket: false route to make sure HTTP handlers are unchanged. The new assertions fail without the fix.

Fixes #314

@Tony133
Tony133 marked this pull request as ready for review October 1, 2026 08:13
@Tony133
Tony133 requested a review from a team October 1, 2026 08:51

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

thanks!

@ilteoood
ilteoood merged commit 51a121c into main Oct 3, 2026
20 checks passed
@ilteoood
ilteoood deleted the fix/route-websocket-handler-types branch October 3, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full declaration syntax is not typed correctly for websocket: true

3 participants