Rocket.Chat.ReactNative icon indicating copy to clipboard operation
Rocket.Chat.ReactNative copied to clipboard

fix: add proper type for room in RoomContext

Open deepak0x opened this issue 2 months ago • 1 comments

I fixed a type-safety issue in RoomContext by replacing the any type used for the room property with a proper union type called TRoomContextRoom. This brings back full TypeScript checking and also removes a blocker for migrating RoomView to hooks.

Issue(s)

Fixes bug: #6799


Problem

The room field in IRoomContext was typed as any, which caused problems like:

  • TypeScript couldn’t validate anything
  • It made the RoomView migration to hooks harder
  • There was already a FIXME comment showing this was known technical debt

Solution

I created a new union type named TRoomContextRoom based on how the room value is actually used in IRoomViewState.room.


Details

File updated: app/views/RoomView/context.ts

What I changed:

  • Added the new union type TRoomContextRoom
  • Updated IRoomContext so room uses this new type instead of any
  • Removed the old FIXME comment
  • Added the required imports for ILastMessage and TSubscriptionModel

The new type works fully with the existing code:

  • RoomView already uses data shaped exactly this way
  • ShareView uses TSubscriptionModel, which is part of the union
  • No other files needed updates

Summary by CodeRabbit

  • Refactor
    • Strengthened typing and expanded the room/message context API to improve message editing, quoting, and autocomplete handling.
  • Chores
    • Updated internal declarations and tests to align with the strengthened typings.

Note: No visible UI changes; existing functionality remains unchanged, with behind-the-scenes improvements to message composition and context behavior.

deepak0x avatar Nov 14 '25 22:11 deepak0x

Walkthrough

Introduces stricter typing for rooms: adds TRoomContextRoom, narrows room.t to RoomType, expands IRoomContext with new message/edit/autocomplete APIs, and updates related tests, stack types, definitions, and RoomView initialization to use the new types.

Changes

Cohort / File(s) Summary
Room Context Type Refinement
app/views/RoomView/context.ts
Added exported TRoomContextRoom (union of TSubscriptionModel or partial room shape); changed IRoomContext.room from any to TRoomContextRoom; added imports (ILastMessage, RoomType, TSubscriptionModel); expanded IRoomContext with selectedMessages, editCancel, editRequest, onRemoveQuoteMessage, onSendMessage, setQuotesAndText, getText, and updateAutocompleteVisible.
Room type discriminator tightening
app/views/RoomView/definitions.ts, app/stacks/types.ts
Replaced string literal type for room t with imported RoomType in state/type declarations.
RoomView initialization typing
app/views/RoomView/index.tsx
Cast default/route room object to IRoomViewState['room']; ensure t defaults using RoomType cast ('d' as RoomType) instead of plain string.
Test typing adjustment
app/containers/MessageComposer/MessageComposer.test.tsx
Imported RoomType and cast test fixture room.t to RoomType ('d' as RoomType) for stricter typing; no runtime logic change.
Manifest / package metadata
manifest_file, package.json
Manifest/package files updated (details not provided in summary).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify TRoomContextRoom aligns with existing usages and no incompatible assumptions remain.
  • Confirm RoomType values and casts ('d' as RoomType) match allowed enum/union members.
  • Check newly added IRoomContext method names/signatures against call sites.
  • Ensure no new implicit-any or type assertion issues in downstream files (tests, stacks, index).

Suggested reviewers

  • diegolmello

Poem

A rabbit tweaks the types with care,
Replacing any with structure rare.
Rooms now speak in clearer tone,
Callbacks hop and types have grown. 🐇✨

Pre-merge checks and finishing touches

✅ 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 accurately summarizes the main change: adding proper typing (TRoomContextRoom type) to replace the 'any' type for the room property in RoomContext, which is the primary focus across all modified files.
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

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.

coderabbitai[bot] avatar Nov 14 '25 22:11 coderabbitai[bot]