Closed jahands closed 1 year ago
@kwhitley any chance this could be merged or something similar implemented? Using itty with ES Module Workers, and it's annoying having to explicitly type env and context in every single handler.
oh this is pretty neat! 🤞
While this PR is a good start, I've noticed a number of gaps that are still not fixed by it, unfortunately.
Notably:
RequestProperties
on a per-route level, due to T extends RouterType<RequestProperties, CustomMethods>
on Route
RequestProperties
than its parentI'll take a stab at fixing those if I get a chance.
Sorry for dropping this one @jahands! I eventually just started over this weekend and re-wrote a lot of the typings (with the help of GPT4) to allow for a kind of split scenario:
Check it out here and let me know what you think! https://itty.dev/itty-router/typescript
That looks great! Thanks!
This allows strict typing of requests in handlers by passing a generic to the router. Added examples in the tests
Users should prefer to use this over taking advantage of GenericTraps that don't have type info
Methodology
I started by adding a generic
RequestType
inRouteHandler
, and then added the generic to everything that started getting TS errors because of this change. No functionality changes.