Closed paulrostorp closed 8 months ago
Weird... in our own example testbed, we have a situation that mirrors your own. We can see it working fine here:
Oh wow... when switching the first param to use/union IRequestStrict
(shown above) instead of IRequest
(default, and what you used), it works... definitely a bug. Good catch!
So this stems from the following:
I've modified the type definition to explicitly check both the first and second param. If either have been modified, it uses the universal route.
This will roll out in 4.1x
with several other changes - great catch @paulrostorp!
Found some issues, so this created a deep dive...
I've done a pretty heavy rework on the internals, which now allows a MUCH more robust usage.
@kwhitley Are the changes you mentioned on the v4.x
branch?
These are being included in the v5.x release that's being finalized this week (with any luck.... I just have to document the CORS changes and migration guide).
Once this is live, I'll backport the types to v4.x as well - but that said, I'd recommend migrating on to v5, as it's adding a lot of power while allowing your own code to shrink further :)
Nice, thanks, v5 is looking great !
Heads up - v5 is out, and we have a guide on the additional args here: https://itty.dev/itty-router/typescript/additional-arguments
I still have some work to do with animated GIFs and such showing the typing in effect, but it should all be working now, across all 3 routers! :)
Ofc certainly re-open if v5 is still having issues :)
Once this is stable, I'll start working backwards to patch up 4.x as much as possible, start adding deprecation notices to things like router.handle
, etc. :)
Describe the Issue
Following the typescript example for "additional types" (https://itty.dev/itty-router/typescript):
Example Router Code
In the code above, the type of
ctx
isany
.In
router.handle
, the type is propagated properlyExpected Behavior
The type of the second route handler argument should be of type
ExecutionContext
.Actual Behavior
The type of the second route handler argument is
any
.Environment (please complete the following information):