Skip to content

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

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

fix(event-handler): add overloads to route() for typed validation context#5052
dreamorosi merged 2 commits intomainfrom
fix/route-overloads

Conversation

@svozza
Copy link
Copy Markdown
Contributor

@svozza svozza commented Feb 28, 2026

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
Comment thread packages/event-handler/src/http/Router.ts
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

@dreamorosi dreamorosi left a comment

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Type error when using request context in event handler route method

2 participants