-
-
Notifications
You must be signed in to change notification settings - Fork 468
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
Improve middleware type definition #1918
Improve middleware type definition #1918
Conversation
🦋 Changeset detectedLatest commit: 5a0c65e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Great fix, and great test! Happy to merge this, but first we need a |
Thank you! I've added a |
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.
Thank you!
With this change, it is no longer possible to have classes implement the class MyMiddleware implements Middleware { ... } Results in:
|
Changes
This PR updates the Middleware type definition to ensure that either
onRequest
oronResponse
must be provided, as reflected in the error:(see #1916)
The new type definition introduces a union that enforces this behavior, allowing the absence of both methods to be detected at compile time.
How to Review
Please review the changes to ensure that the new type definition accurately reflects the expected behavior. The key point is that a type error should occur only if neither onRequest nor onResponse is provided. Additionally, please check that existing middleware implementations are unaffected by this change.
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)Closes #1916