fix: add proper type for room in RoomContext
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
FIXMEcomment 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
IRoomContextsoroomuses this new type instead ofany - Removed the old FIXME comment
- Added the required imports for
ILastMessageandTSubscriptionModel
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.
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
TRoomContextRoomaligns with existing usages and no incompatible assumptions remain. - Confirm
RoomTypevalues and casts ('d' as RoomType) match allowed enum/union members. - Check newly added
IRoomContextmethod 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,
Replacinganywith 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.
Comment @coderabbitai help to get the list of available commands and usage tips.