-
-
Notifications
You must be signed in to change notification settings - Fork 850
feat(types): passing middleware types #4393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(types): passing middleware types #4393
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #4393 +/- ##
=======================================
Coverage 91.25% 91.26%
=======================================
Files 171 171
Lines 10915 10927 +12
Branches 3146 3149 +3
=======================================
+ Hits 9961 9973 +12
Misses 953 953
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
075451a to
531571c
Compare
…ve response extraction for status codes
…return type in validator middleware
531571c to
e405f66
Compare
|
Hi @slawekkolodziej ! Awesome! It comes true and all tests passed. One thing we have to consider is the performance. I took the The This PR branch: The So, we should choose.
Both are important. It's a common problem with the performance of type inference. If the project becomes big, the PRC will be super slow, and the editor may hang. However, making behavior expected is also important for achieving better DX. I think we can accept this PR, though bringing the performance degradation since making consistency is significant, and we may resolve the performance issue in other ways. Anyway, I'll review the details later. Thanks! |
|
Regarding performance, I like to think that TS7, once released, will make this problem go away completely. |
|
I’ve made no contribution here so take this with a grain of salt, but I am eagerly awaiting this PR. Typesafe errors/responses from middleware is a huge upgrade to the usefulness of RPC. It allows us to compose behaviors using the elegant Hono middleware system AND retain type safety end to end - it will result in a better user experience as devs will be able to easily understand via the type system what errors may result from a particular RPC call and handle them in the UI accordingly. Both project references/composite builds and of course TSGO will likely more than compensate for any performance impact. |
|
Yes. This PR is great. I'll merge this later! |
|
My bad for being late. I think you can merge it. |
yusukebe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
I'll merge this into the
If you can fix it and create a PR for it. Please make a PR against the Thank you for the great work!! |
|
Great news! Regarding that fix - it's already there! I pushed the fix in one of my subsequent commits (when I removed the 'draft' label). My bad, I should have update original my MR message. I'll create another PR for zod & valibot middlewares to have proper type inference with those two (I already have working code locally). I think those two can serve as good starting point for other middleware's maintainers. |
This PR fixes #2719
It's somewhat based off this draft PR: #4252 (I copied majority of tests from there, thanks!)
After some more changes in validator middlewares (I already adjusted
@hono/zod-validatorand@hono/valibot-validator) it gives proper error codes through RPC.The code here already works & should be passing all tests. The only outstanding thing I am aware of is adjusting types for
app.use. From type like this:into one that passes 4 params to MiddlewareHandler:
Without it
app.useis complaining about invalid type when you try to pass a 'typed middleware' to it. I should be able to adjust this soon.The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code