Skip to content
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

Merged
merged 3 commits into from
Jan 12, 2024

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jan 11, 2024

@@ -10,22 +10,35 @@ import {
} from './handlers/HttpHandler'
import type { Path, PathParams } from './utils/matching/matchRequestUrl'

export type HttpRequestHandler = <
Copy link
Member Author

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 custom http.get() function.
  • HttpHandler is not http.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.

@kettanaito
Copy link
Member Author

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.

@mattcosta7
Copy link
Contributor

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<
Copy link
Member Author

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.

Copy link
Contributor

@mattcosta7 mattcosta7 left a 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

@kettanaito kettanaito merged commit 8624f31 into main Jan 12, 2024
11 checks passed
@kettanaito kettanaito deleted the fix/improve-resolver-annotations branch January 12, 2024 14:29
@kettanaito
Copy link
Member Author

Released: v2.0.14 🎉

This has been released in v2.0.14!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom response resolver annotations
2 participants