Skip to content

Conversation

@eL1fe
Copy link

@eL1fe eL1fe commented Dec 29, 2025

Summary

Problem

The handle method was returning Promise<any> instead of Promise<Response> because:

  1. composeGeneralHandler creates a function via Function() constructor, which returns any
  2. Neither handle nor fetch had explicit return type annotations
  3. TypeScript inferred the type as any

Solution

Added explicit return types:

  • handle now returns Promise<Response>
  • fetch getter now returns (request: Request) => Response | Promise<Response>

Test plan

Summary by CodeRabbit

  • Refactor
    • Enhanced API type signatures with explicit return type annotations to improve type safety and provide clearer contracts for request handling and response processing.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes elysiajs#1630

The `handle` method was returning `Promise<any>` instead of `Promise<Response>`
because `composeGeneralHandler` creates a function via `Function()` which
returns `any`. Added explicit return types to both `handle` and `fetch` to
restore proper type inference.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Walkthrough

This PR restores explicit type annotations to two public method signatures in the Elysia class: the handle method now explicitly returns Promise<Response>, and the fetch getter declares its return type as (request: Request) => Response | Promise<Response>. No functional behavior changes.

Changes

Cohort / File(s) Change Summary
Type Signature Restoration
src/index.ts
handle method explicitly returns Promise<Response> (fixes regression from 1.4.19); fetch getter explicitly typed as (request: Request) => Response | Promise<Response> to enforce type consistency at public API surface

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A Promise lost, now found once more,
Type safety restored to our beloved store!
Promise<Response> shines bright and clear,
No more any shadows—type safety here! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: restoring the handle() method's return type to Promise, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #1630 by restoring handle() return type to Promise and adding explicit type annotation to the fetch getter.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving the type inference issue in handle() and fetch getter, with no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f751caf and 05af4b8.

📒 Files selected for processing (1)
  • src/index.ts
🔇 Additional comments (2)
src/index.ts (2)

8047-8047: LGTM! Explicit return type correctly restores type safety.

The addition of : Promise<Response> to the handle method properly addresses issue #1630. Since handle is async and delegates to this.fetch(request), the Promise wrapper is guaranteed, making Promise<Response> the correct return type.


8054-8054: LGTM! Explicit function signature prevents type inference issues.

The explicit return type (request: Request) => Response | Promise<Response> correctly types the fetch getter. This ensures TypeScript doesn't infer any from the dynamically composed handlers created by composeGeneralHandler or createDynamicHandler, directly addressing the root cause described in the PR objectives.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

handle used to return a Promise<Response> not it returns Promise<any>

1 participant