Skip to content

fix(event-handler): add overloads to route() for typed validation context - #5052

Merged
dreamorosi merged 2 commits into
mainfrom
fix/route-overloads
Mar 9, 2026
Merged

dreamorosi merged 2 commits into
mainfrom
fix/route-overloads

Conversation

@svozza

@svozza svozza commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Router.route() did not correctly infer handler parameter types — when destructuring (e.g., {req}), TypeScript inferred any because the handler was typed as a union of RouteHandler | TypedRouteHandler. This adds overloads so the handler type is determined by whether validation is present in the options.

Changes

  • Added two overloads to route(): without validation the handler receives RequestContext; with validation it receives TypedRequestContext (with the valid property)
  • Extracted the implementation into a private #registerRoute method so internal callers bypass the public overloads
  • Added unit tests for route() with validation and type-level tests

Issue number: closes #5051


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size Bot added the size/L PRs between 100-499 LOC label Feb 28, 2026
@svozza
svozza requested a review from dreamorosi February 28, 2026 08:09

@dreamorosi dreamorosi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this

@dreamorosi
dreamorosi merged commit dae12e4 into main Mar 9, 2026
50 checks passed
@dreamorosi
dreamorosi deleted the fix/route-overloads branch March 9, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L PRs between 100-499 LOC

2 participants