-
Notifications
You must be signed in to change notification settings - Fork 0
perf(types): reduce type instantiations for Promise<void> middleware #4
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
perf(types): reduce type instantiations for Promise<void> middleware #4
Conversation
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.
Pull request overview
This PR optimizes TypeScript type instantiations for middleware that returns Promise<void> by refactoring several key utility types to reduce computational overhead during type checking.
Key Changes:
- Refactored
Promise<void>handling to returnneverinMergeTypedResponse, eliminating redundant conditional checks in downstream types - Unrolled
IntersectNonAnyTypestype with explicit cases for arrays up to 10 elements to reduce recursive type instantiations - Restructured
ToSchemato handlenevercase early and movedIsAnycheck into the conditional branch
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| export type IntersectNonAnyTypes<T extends any[]> = T extends [] | ||
| ? {} | ||
| : T extends [infer H1] | ||
| ? ProcessHead<H1> | ||
| : T extends [infer H1, infer H2] | ||
| ? ProcessHead<H1> & ProcessHead<H2> | ||
| : T extends [infer H1, infer H2, infer H3] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5, infer H6] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> & ProcessHead<H6> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5, infer H6, infer H7] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> & ProcessHead<H6> & ProcessHead<H7> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5, infer H6, infer H7, infer H8] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> & ProcessHead<H6> & ProcessHead<H7> & ProcessHead<H8> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5, infer H6, infer H7, infer H8, infer H9] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> & ProcessHead<H6> & ProcessHead<H7> & ProcessHead<H8> & ProcessHead<H9> | ||
| : T extends [infer H1, infer H2, infer H3, infer H4, infer H5, infer H6, infer H7, infer H8, infer H9, infer H10] | ||
| ? ProcessHead<H1> & ProcessHead<H2> & ProcessHead<H3> & ProcessHead<H4> & ProcessHead<H5> & ProcessHead<H6> & ProcessHead<H7> & ProcessHead<H8> & ProcessHead<H9> & ProcessHead<H10> | ||
| : T extends [infer Head, ...infer Rest] | ||
| ? ProcessHead<Head> & IntersectNonAnyTypes<Rest> | ||
| : {} |
Copilot
AI
Nov 27, 2025
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.
[nitpick] The IntersectNonAnyTypes type has been unrolled for performance optimization with hardcoded cases up to 10 elements. However, this approach sacrifices maintainability for performance gains. Consider adding a comment explaining:
- Why the unrolling stops at 10 elements
- The performance tradeoff being made
- What happens with arrays longer than 10 elements (falls back to recursive case)
This will help future maintainers understand the design decision.
No description provided.