refactor: remove unsafe any cast in StreamPresence implementation#39377
refactor: remove unsafe any cast in StreamPresence implementation#39377sahillllllllll-bit wants to merge 2 commits into
any cast in StreamPresence implementation#39377Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughChanged the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/app/notifications/server/lib/Presence.ts`:
- Around line 75-76: Change the signature of getInstance to constrain the name
parameter to the literal type 'user-presence' (e.g., name: 'user-presence' =
'user-presence') so the method returns IStreamer<'user-presence'> without
needing casts; update the getInstance declaration and any callers if necessary,
and then remove the redundant type assertion used when instantiating
StreamPresenceImpl inside getInstance (the assertion on the new (...)
expression). Target the getInstance function and the inner StreamPresenceImpl
class to ensure types line up.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 34334679-758c-434d-9155-b2f7775f7f36
📒 Files selected for processing (1)
apps/meteor/app/notifications/server/lib/Presence.ts
📜 Review details
⏰ 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). (1)
- GitHub Check: cubic · AI code reviewer
🧰 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:
apps/meteor/app/notifications/server/lib/Presence.ts
🧠 Learnings (4)
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Applied to files:
apps/meteor/app/notifications/server/lib/Presence.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
Applied to files:
apps/meteor/app/notifications/server/lib/Presence.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/app/notifications/server/lib/Presence.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/app/notifications/server/lib/Presence.ts
🔇 Additional comments (1)
apps/meteor/app/notifications/server/lib/Presence.ts (1)
77-83: Line 82 correctly handles the actual data structure; reconsider the unsafe type assertion.The review's concern about
options.argsis unfounded. The client passes presence data directly as flat properties ({ added: [...], removed: [...] }), not nested underoptions.args. Line 82's extraction directly from the options object matches the actual usage pattern at apps/meteor/client/lib/presence.ts:58-60. The base Streamer pattern foroptions.argsis not applicable here since this is an intentional override for a different data flow.However, the type assertion
as UserPresenceStreamPropsremains unsafe—if options lacksaddedorremovedproperties, destructuring produces undefined silently. A guard check is prudent:const parsed = typeof options !== 'boolean' ? options : {}; const added = Array.isArray(parsed.added) ? parsed.added : []; const removed = Array.isArray(parsed.removed) ? parsed.removed : [];The second issue at line 98—
name as 'user-presence'—is a legitimate type safety concern: casting a string parameter to a literal type is unsound, though likely intentional given the class generic constraint.
…ve unnecessary type assertion
Summary
This change removes the unsafe
as anycast used when instantiating theStreamPresencestreamer.Instead of bypassing TypeScript checks with
any, the returned instance is now properly typed using the expectedIStreamer<'user-presence'>interface.Using
anydisables TypeScript's type safety and can hide potential type mismatches during refactoring or future changes. Since the streamer already conforms to the expected interface, we can safely replace the cast with a more explicit and type-safe assertion.Changes
as anycast from theStreamPresenceinstantiation.IStreamer<'user-presence'>type assertion for the returned instance.Impact
any..
Summary by CodeRabbit