Skip to content

Conversation

@TheRazorbill
Copy link

@TheRazorbill TheRazorbill commented Feb 11, 2026

Proposed changes

This PR improves TypeScript type safety in the Callbacks utility by:

  • Replacing loose generic constraints ([key: string]: (item: any, constant?: any) => any)
    with stricter Record<string, ...Signature> types
  • Introducing semantic callback signature types:
    • EventLikeCallbackSignature (side-effect callbacks)
    • ChainedCallbackSignature (value-transforming callbacks)
  • Reducing unnecessary any casts in the static create method
  • Improving inline documentation with clearer JSDoc comments
  • Updating the callback constant parameter to be optional for better flexibility

These changes improve maintainability and typing accuracy while preserving backward compatibility and runtime behavior.


Proposed changes (including screenshots)

Before / After

image image

Issue(s)

N/A (typing improvement / refactor)


Steps to test or reproduce

  • Run TypeScript checks locally
  • Ensure the project builds successfully with no type errors

Example:

yarn lint
yarn test


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Refactor**
  * Strengthened callback and event typings with clearer semantic signatures and stricter generic constraints for safer development and better IDE autocomplete.
  * Made the callback "constant" parameter optional for more flexible usage.
  * Introduced a reusable action-listener type and a typed avatar-path function; narrowed the hook return type to that signature.
  * No user-facing behavior changed; backward compatible.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

- Replace generic constraints `[key: string]: (item: any, constant?: any) => any` with `Record<string, ...Signature>` types
- Add semantic callback signature types: EventLikeCallbackSignature and ChainedCallbackSignature
- Reduce unnecessary `any` type casts in static create method
- Make callback constant parameter optional for better flexibility
- Improve JSDoc comments for better type documentation
- All existing tests pass without breaking changes

This improves type safety while maintaining backward compatibility with existing callback implementations.
Copilot AI review requested due to automatic review settings February 11, 2026 21:49
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 11, 2026

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 Feb 11, 2026

⚠️ No Changeset found

Latest commit: 1bc6538

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 Feb 11, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Tightens TypeScript typings across UI packages: refactors Callbacks signatures and generics, introduces a typed ActionEventListener for action manager listeners, and adds a structured GetRoomPathAvatar type (propagated to the useRoomAvatarPath hook); also adds a changeset entry documenting the callbacks typing change.

Changes

Cohort / File(s) Summary
Changeset Entry
\.changeset/improve-callbacks-typing.md
Adds a changeset documenting the Callbacks typing refactor.
Callbacks Type Refactoring
packages/ui-client/src/lib/callbacks/Callbacks.ts
Adds EventLikeCallbackSignature and ChainedCallbackSignature; switches generics to Record<string, ...>; updates Callbacks class signature, static create overloads/return typing, internal initialization, and makes callback constant parameter optional in public interfaces.
Action Manager Listener Types
packages/ui-contexts/src/ActionManagerContext.ts
Adds ActionEventListener<T> type and replaces inline (data: any) listener types with ActionEventListener<UiKit.ServerInteraction> for on/off overloads.
Avatar URL Getter Typing
packages/ui-contexts/src/AvatarUrlContext.ts
Adds GetRoomPathAvatar type (object-parameter) and replaces getRoomPathAvatar: (...args: any) => string with GetRoomPathAvatar.
Hook Return Type Narrowing
packages/ui-contexts/src/hooks/useRoomAvatarPath.ts
Imports GetRoomPathAvatar and narrows useRoomAvatarPath return type to GetRoomPathAvatar (no runtime behavior changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hopped through lines of code so snappy,
Swapped loose any for types that’re happy,
Listeners and avatars now neatly named,
Callbacks tightened — nothing renamed,
A rabbit cheers — typings all tidy! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(ui-client): improve Callbacks class typing v2' accurately summarizes the main change—a refactor to improve TypeScript typing in the Callbacks class by introducing semantic callback signature types and stricter generic constraints.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

- Replace generic `any` types with typed ActionEventListener<T> generic
- Make ActionEventListener return void (idiomatic for event handlers)
- Type listener parameter with UiKit.ServerInteraction for improved type safety
- Export GetRoomPathAvatar type for reuse across package
- Improve type specificity with explicit function overloads
- Maintain destructuring pattern for 'busy' event listener ergonomics
- All tests pass without breaking changes

Improvements:
- Better type inference at callsites
- Generic type parameter supports future extensions
- Exported types prevent any leakage in dependent code
- JSDoc documentation for clarity
Copy link
Contributor

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 refactors packages/ui-client’s legacy Callbacks utility to improve TypeScript typing by introducing semantic callback signature aliases and tightening generic constraints.

Changes:

  • Introduces EventLikeCallbackSignature / ChainedCallbackSignature helper types and uses them in Callbacks generic constraints.
  • Refactors Callbacks.create factory typing and reduces any casting.
  • Makes the “constant” callback parameter optional in the deprecated Cb helper type and adds a changeset.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/ui-client/src/lib/callbacks/Callbacks.ts Adds new signature types, changes generic constraints, and refactors Callbacks.create/Cb typing.
.changeset/improve-callbacks-typing.md Declares a patch release note for the typing refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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: 2

🤖 Fix all issues with AI agents
In `@packages/ui-client/src/lib/callbacks/Callbacks.ts`:
- Around line 236-241: Remove the redundant no-op cast by deleting the typedHook
variable and use the existing hook parameter directly; update the return object
so add/remove/run call callbacks.add(hook,...), callbacks.remove(hook,...), and
callbacks.run(hook,...) instead of referencing typedHook, ensuring you only
change the alias usage and not the callbacks methods themselves.
- Around line 16-26: Change EventLikeCallbackSignature to return void (not "void
| unknown") so it is distinct from ChainedCallbackSignature; update the type
definition named EventLikeCallbackSignature in Callbacks.ts to enforce void and
keep ChainedCallbackSignature as returning unknown, and update any related uses
(e.g., event callbacks like afterCreateChannel, afterSaveMessage, usernameSet in
clientCallbacks.ts) if necessary to satisfy the stricter void return. Also
remove the redundant cast "const typedHook = hook as string" and use the
existing hook parameter directly (the parameter named hook is already a string),
eliminating the unused/duplicative typedHook variable.
🧹 Nitpick comments (1)
packages/ui-client/src/lib/callbacks/Callbacks.ts (1)

16-19: JSDoc comments added on type declarations.

The coding guideline for **/*.{ts,tsx,js} states: "Avoid code comments in the implementation." The file already has JSDoc comments on methods (lines 125–132, 205–212, etc.), so this is consistent with the existing pattern, but these new comments are additions in this PR.

As per coding guidelines, **/*.{ts,tsx,js}: "Avoid code comments in the implementation".

Also applies to: 22-25

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d9eb6a and 4ab8b3f.

📒 Files selected for processing (2)
  • .changeset/improve-callbacks-typing.md
  • packages/ui-client/src/lib/callbacks/Callbacks.ts
🧰 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/ui-client/src/lib/callbacks/Callbacks.ts
🧬 Code graph analysis (1)
packages/ui-client/src/lib/callbacks/Callbacks.ts (2)
apps/meteor/server/lib/callbacks.ts (1)
  • callbacks (218-226)
packages/livechat/src/widget.ts (1)
  • callback (509-511)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Agent
🔇 Additional comments (3)
packages/ui-client/src/lib/callbacks/Callbacks.ts (2)

40-43: LGTM!

The updated generic constraints using Record<string, ChainedCallbackSignature> and Record<string, EventLikeCallbackSignature> are cleaner than the previous index-signature approach and compatible with the existing usage in apps/meteor/server/lib/callbacks.ts.


250-257: LGTM!

Making constant optional in the Cb type is consistent with how it's treated throughout the class (e.g., line 29, line 149, line 203) and aligns with the runtime behavior where the constant is frequently omitted.

.changeset/improve-callbacks-typing.md (1)

1-5: LGTM!

Changeset correctly identifies this as a patch — appropriate for a non-breaking typing improvement.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/ui-client/src/lib/callbacks/Callbacks.ts">

<violation number="1" location="packages/ui-client/src/lib/callbacks/Callbacks.ts:20">
P2: The return type `void | unknown` simplifies to `unknown` in TypeScript (since `unknown` is the top type), making `EventLikeCallbackSignature` structurally identical to `ChainedCallbackSignature`. This defeats the semantic distinction between side-effect callbacks and value-transforming callbacks. Consider using just `void` to enforce the intended behavior for event-like callbacks.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…ibility

- Change EventLikeCallbackSignature to return only void (not void | unknown)
- Replace unknown with any in callback parameters for strictFunctionTypes compatibility
- Update Callback<H> type to use any instead of Promise<unknown> for consistency
- Add overload to create() method for backward compatibility with legacy code
- Fix Cb.add return type to () => void to match actual implementation
- Remove unnecessary type cast in create() method
Copy link
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TheRazorbill
Copy link
Author

I've opened this second PR to refine the Callbacks utility typing in @rocket.chat/ui-client. My goal was to replace the loose any constraints with stricter semantic signatures (EventLike and Chained) to prevent future typing regressions.

I have already:

Addressed the feedback from the AI reviewers regarding return types (void vs unknown).
Included a changeset as this affects multiple packages.
Ensured backward compatibility with existing callback implementations.
I'd appreciate your thoughts on this approach. Does this align with how we want to handle utility typings moving forward?
Whenever you have time to check it, please let me know if any further changes are needed for the approval.

Thanks!

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