Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bufferings
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings November 27, 2025 14:07
Copy link

Copilot AI left a 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 return never in MergeTypedResponse, eliminating redundant conditional checks in downstream types
  • Unrolled IntersectNonAnyTypes type with explicit cases for arrays up to 10 elements to reduce recursive type instantiations
  • Restructured ToSchema to handle never case early and moved IsAny check 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.

Comment on lines +2387 to 2411
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>
: {}
Copy link

Copilot AI Nov 27, 2025

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:

  1. Why the unrolling stops at 10 elements
  2. The performance tradeoff being made
  3. What happens with arrays longer than 10 elements (falls back to recursive case)

This will help future maintainers understand the design decision.

Copilot uses AI. Check for mistakes.
@bufferings bufferings closed this Nov 27, 2025
@bufferings bufferings deleted the fix/types-middleware-void-trial branch November 27, 2025 14:15
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.

2 participants