Skip to content

Conversation

@Jaysinh146
Copy link

@Jaysinh146 Jaysinh146 commented Dec 14, 2025

Proposed changes

This PR resolves a TypeScript build failure occurring in packages/http-router when using Node 22 / TypeScript 5.x.

Technical Changes:

  1. Strict Key Cast: Casts method.toLowerCase() to keyof typeof this.innerRouter. This fixes the issue where TS could not verify the string was a valid router key.
  2. Function Cast: Explicitly casts the retrieved router property to Function. This prevents the TS2349: Expression is not callable error by assuring TS that we are accessing a method, not a property array (like .routes).
  3. Context Typing: Types the callback parameter (c) as any to resolve the TS7006: Implicit any error.

These changes allow the project to build successfully on the latest Node versions while preserving the existing runtime logic.

Issue(s)

Closes #37801

Steps to test or reproduce

  1. Checkout the develop branch and run yarn build in packages/http-router. Observe the TypeScript errors (TS2345, TS7006).
  2. Checkout this PR branch.
  3. Run yarn build in packages/http-router.
  4. Observe that the build completes successfully with no errors.

Further comments

Thanks to @17dhruv for identifying the root cause and providing the reproduction steps in the issue.

Summary by CodeRabbit

  • Refactor
    • Improved internal router invocation to be more flexible while preserving runtime behavior.
    • Made request/handler callback typing explicit to clarify handler expectations and improve consistency.

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Dec 14, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2025

⚠️ No Changeset found

Latest commit: 5d3b750

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 14, 2025

Walkthrough

A TypeScript-only change in packages/http-router/src/Router.ts narrows dynamic Hono router method access by computing a lowercased method key and casting the inner router to a record of that method type, and it explicitly types the handler parameter as (c: Context) => Promise<void> (async) to satisfy TS 5.x.

Changes

Cohort / File(s) Summary
Router typing fix
packages/http-router/src/Router.ts
Replace direct dynamic access this.innerRouter[method.toLowerCase()] with a computed methodKey and cast innerRouter to Record<typeof methodKey, RouteMethod> before invocation; tighten handler param typing to an explicit async (c: Context) => { ... }.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single-file, type-focused change but affects runtime callsite typing.
  • Review focus:
    • packages/http-router/src/Router.ts — ensure the RouteMethod definition and cast align with Hono types and that the explicit Context matches project types.
    • Confirm no unintended narrowing or loss of overloads for router methods.

Poem

🐇
I thumped a key, then lowered the case,
Whispered to types, "now find your place."
A tiny cast, a context named,
Build sings again — no error blamed,
Hops and carrots, tidy code embraced. 🥕

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: resolving a TypeScript typing issue in the http-router package for Node 22 compatibility.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from #37801: applying type-safe casts to resolve TS errors (TS2345, TS2349, TS7006) and enabling successful builds on Node 22/TypeScript 5.x.
Out of Scope Changes check ✅ Passed All changes in Router.ts are directly scoped to resolving the dynamic Hono router method access typing issue; no unrelated modifications detected.
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: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b5a07c6 and c2dde15.

📒 Files selected for processing (1)
  • packages/http-router/src/Router.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/http-router/src/Router.ts

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.

@CLAassistant
Copy link

CLAassistant commented Dec 14, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Jaysinh146
❌ Jaysinh Patankar


Jaysinh Patankar seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Jaysinh146 Jaysinh146 closed this Dec 14, 2025
@Jaysinh146 Jaysinh146 force-pushed the fix/37801-node-22-typing branch from 2871a3e to 8bf0bab Compare December 14, 2025 18:19
@Jaysinh146 Jaysinh146 reopened this Dec 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b6b4ac3 and 800d305.

📒 Files selected for processing (1)
  • packages/http-router/src/Router.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/http-router/src/Router.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 36868
File: packages/http-router/src/Router.ts:416-425
Timestamp: 2025-09-15T13:10:30.049Z
Learning: In packages/http-router/src/Router.ts, the dispatch() method's use of replaceAll('//', '/') on the full path is acceptable because URL normalization and query string handling is performed by the caller function before dispatch() is invoked.
📚 Learning: 2025-09-15T13:10:30.049Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 36868
File: packages/http-router/src/Router.ts:416-425
Timestamp: 2025-09-15T13:10:30.049Z
Learning: In packages/http-router/src/Router.ts, the dispatch() method's use of replaceAll('//', '/') on the full path is acceptable because URL normalization and query string handling is performed by the caller function before dispatch() is invoked.

Applied to files:

  • packages/http-router/src/Router.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/http-router/src/Router.ts (1)

197-197: Avoid as Function; cast to a callable route-method type instead (keeps safety without changing runtime).
Right now keyof typeof this.innerRouter is too broad and as Function disables call-signature checking; a narrower callable type still fixes TS2349 while preserving intent.

-		(this.innerRouter[method.toLowerCase() as keyof typeof this.innerRouter] as Function)(`/${subpath}`.replace('//', '/'), ...middlewares, async (c: Context) => {
+		type RouteMethod = (path: string, ...handlers: MiddlewareHandler[]) => unknown;
+		const methodKey = method.toLowerCase() as Lowercase<Method>;
+		(this.innerRouter as unknown as Record<Lowercase<Method>, RouteMethod>)[methodKey](
+			`/${subpath}`.replace('//', '/'),
+			...middlewares,
+			async (c: Context) => {
 				const { req, res } = c;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 800d305 and b5a07c6.

📒 Files selected for processing (1)
  • packages/http-router/src/Router.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/http-router/src/Router.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 36868
File: packages/http-router/src/Router.ts:416-425
Timestamp: 2025-09-15T13:10:30.049Z
Learning: In packages/http-router/src/Router.ts, the dispatch() method's use of replaceAll('//', '/') on the full path is acceptable because URL normalization and query string handling is performed by the caller function before dispatch() is invoked.
📚 Learning: 2025-09-15T13:10:30.049Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 36868
File: packages/http-router/src/Router.ts:416-425
Timestamp: 2025-09-15T13:10:30.049Z
Learning: In packages/http-router/src/Router.ts, the dispatch() method's use of replaceAll('//', '/') on the full path is acceptable because URL normalization and query string handling is performed by the caller function before dispatch() is invoked.

Applied to files:

  • packages/http-router/src/Router.ts

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.

TypeScript build failure in @rocket.chat/http-router due to incorrect Hono router method typing (Node 22 / TS 5.x)

2 participants