-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
fix: improve custom request handler and resolver annotations #1961
Conversation
kettanaito
commented
Jan 11, 2024
•
edited
Loading
edited
- Fixes Custom response resolver annotations #1955
- Solves How to type async higher-order resolver in Typescript? #1802
@@ -10,22 +10,35 @@ import { | |||
} from './handlers/HttpHandler' | |||
import type { Path, PathParams } from './utils/matching/matchRequestUrl' | |||
|
|||
export type HttpRequestHandler = < |
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.
Confusing terminology here.
HttpRequestHandler
is when people want to create customhttp.get()
function.HttpHandler
is nothttp.get()
interface at all. It's its own thing with.parse()
,.run()
and friends.
I think in the context of the userland, it's fine to call this type a request handler type. It's precisely how we refer to the http.get()
functions in the docs.
Hi, @mattcosta7 👋 Please, would you have a minute to give this change a brief look? The aim here is to improve the way people can annotate custom request handlers and response resolvers in TypeScript by shipping a few utility types. |
Will do, might not have time to look much until this weekend, but i'll try to get eyes on it sooner! |
| MaybeAsyncResponseResolverReturnType<BodyType> | ||
export type AsyncResponseResolverReturnType< | ||
ResponseBodyType extends DefaultBodyType, | ||
> = MaybePromise< |
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.
This is a fantastic change suggested by @Andarist to enable proper return type inference when annotating custom higher-order resolvers. Gold.
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.
Nice, this looks like a great addition that should simply some use-cases
Released: v2.0.14 🎉This has been released in v2.0.14! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |