Skip to content

refactor: improve type safety by removing as any casts in composer components#41566

Open
Rajkaran-122 wants to merge 1 commit into
RocketChat:developfrom
Rajkaran-122:refactor/remove-as-any-casts
Open

refactor: improve type safety by removing as any casts in composer components#41566
Rajkaran-122 wants to merge 1 commit into
RocketChat:developfrom
Rajkaran-122:refactor/remove-as-any-casts

Conversation

@Rajkaran-122

@Rajkaran-122 Rajkaran-122 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

This PR improves TypeScript hygiene by replacing unsafe as any type assertions with strict type guards and generic assertions across various client views.

What Changed

  • Replaced as any on filter object with a proper hasCmd type guard in useComposerBoxPopupQueries.ts.
  • Removed as any and casted to as unknown as Promise<{ app: App }> to strictly match the mutation's onSuccess callback in useInstallApp.tsx.
  • Removed an unnecessary as any spread property inside CategoryDropDownList.tsx by passing the label prop directly.

Why

Overuse of as any breaks the reliability of the TypeScript compiler. This PR guarantees that these React components have robust, compile-time prop and variable validation.

Testing

  • Verified code statically

Checklist

@Rajkaran-122
Rajkaran-122 requested a review from a team as a code owner July 25, 2026 06:12
@dionisio-bot

dionisio-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

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

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 32b82c6

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

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The changes replace unsafe casts with explicit typing in marketplace code and add runtime validation for composer popup filters before slash-command lookup.

Changes

Marketplace typing

Layer / File(s) Summary
Marketplace prop and response typing
apps/meteor/client/views/marketplace/...
Category options pass labels directly, and private-app installation responses are typed as { app: App }.

Composer filter validation

Layer / File(s) Summary
Popup preview command guard
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
Popup preview gating validates that the filter contains a string cmd before reading slash-command preview metadata.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: chore

Suggested reviewers: tassoevan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title captures the type-safety refactor and cast removal, which is a real part of the changeset.

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.

@Rajkaran-122 Rajkaran-122 changed the title refactor: add proper TypeScript types for CannedResponse model refactor: improve type safety by removing as any casts in composer components Jul 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx`:
- Around line 43-46: Update the useUpload mutation callback in useInstallApp to
handle UploadResult by rejecting when result.success is false and returning the
typed success payload, removing the unknown/type-unsafe casts. Define a separate
app-install/update endpoint result type in `@rocket.chat/rest-typings` and apply
it to the /apps and /apps/update contracts so useMutation receives the correct
typed response.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a13445c-6ac7-40db-bd6c-d3e1187b0630

📥 Commits

Reviewing files that changed from the base of the PR and between 6dc66fb and 32b82c6.

📒 Files selected for processing (3)
  • apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx
  • apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (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/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx
  • apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
🧠 Learnings (6)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx
  • apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx
  • apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.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/client/views/room/composer/hooks/useComposerBoxPopupQueries.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/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
🔇 Additional comments (2)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts (1)

18-26: LGTM!

apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx (1)

17-17: LGTM!

Comment on lines +43 to 46
return uploadAppEndpoint(fileData) as unknown as Promise<{ app: App }>;
},

onSuccess: (data: { app: App }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locate target file and upload helper:"
fd -a 'useInstallApp\.tsx|useUpload|uploadAppEndpoint|apps/update|apps' . | sed 's#^\./##' | head -200

echo
echo "Target file excerpt:"
sed -n '1,140p' apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx 2>/dev/null || true

echo
echo "Search uploadAppEndpoint definitions/imports:"
rg -n "uploadAppEndpoint|useUpload|\\bapps/.+upload|useMutation\\(.*upload|Upload\\(" apps -g '*.{ts,tsx,js}' --glob '!**/node_modules/**' --glob '!**/.git/**' | head -300

Repository: RocketChat/Rocket.Chat

Length of output: 13792


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "useUpload hook:"
sed -n '1,220p' packages/ui-contexts/src/hooks/useUpload.ts

echo
echo "upload-related market-place/test references:"
rg -n "POST /apps|/apps\\b|/apps/update|AppUpload|uploadApp|app:|upload" apps/meteor/app/apps apps/meteor/public apps/meteor/server/api apps/meteor/tests apps/meteor/client/views/marketplace packages rest-typings --glob '*.{ts,tsx,js,json}' | head -300

echo
echo "apps REST API files:"
fd -a 'apps.*\.(ts|tsx|js)$|.*apps.*\.(ts|tsx|js)$' apps/meteor/server/api apps/meteor/app/apps --ignore-case | head -200

Repository: RocketChat/Rocket.Chat

Length of output: 38964


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "useEndpointUploadMutation type context:"
sed -n '1,120p' apps/meteor/client/hooks/useEndpointUploadMutation.ts

echo
echo "API endpoint candidates that handle multipart app uploads:"
rg -n "POST|POST_API|api\\.v1\\.post|addRoute\\(['\"]apps|/apps|uploadApp|uploadUpdate|apps/update|AppClientUpload|uploadToEndpoint" apps/meteor/server/api apps/meteor/app apps/meteor/ee/server apps/meteor/client packages/ui-contexts src --glob '*.{ts,tsx,js}' | head -400

echo
echo "package ui-contexts contexts/type files:"
fd -a 'ServerContext\.ts|upload.*\.ts|api.*\.ts|Endpoint.*\.ts' packages/ui-contexts src --ignore-case | head -100

Repository: RocketChat/Rocket.Chat

Length of output: 50378


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "ServerProvider upload/result helper context:"
sed -n '1,110p' apps/meteor/client/providers/ServerProvider.tsx

echo
echo "Focused search for APP upload endpoints:"
rg -n "POST_API|api\.v1\.post|addRoute\\(['\"]apps|apiServer|Router|install|private|upload|\\.update\\(|apps/update|/apps\\b" apps/meteor/server/api apps/meteor/app/apps --glob '*.{ts,tsx,js}' | head -250

echo
echo "REST typings app routes relevant to install/update:"
fd -a 'apps.*\.(ts|tsx|json)$|.*apps.*\.(ts|tsx|json)$' packages/rest-typings -i | while read -r f; do echo "--- $f"; rg -n "/apps|apps/update|private|install|upload" "$f" || true; done

Repository: RocketChat/Rocket.Chat

Length of output: 34549


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "REST typings package files:"
git ls-files packages/rest-typings | sed -n '1,200p'

echo
echo "Search for App upload schemas/endpoints in repos:"
rg -n "EndpointResult|OperationResult|POST::|apps/update|apps'\\b|/apps|upload.*App|App.*upload|app:.*upload|apps.private|apps.private|apps.private-create|private-app|private" packages/rest-typings src --glob '*.{ts,tsx,js,json}' | head -300 || true

echo
echo "Client tests/mocks around app upload response shape:"
rg -n "POST /api/apps|/api/apps|\\bapp:|response\\.|body\\.|success|\\.app|installLocalTestPackage|private-apps-upload" apps/meteor/tests apps/meteor/client/providers apps/meteor/tests/mocks packages/ui-contexts --glob '*.{ts,tsx,js}' | head -300

Repository: RocketChat/Rocket.Chat

Length of output: 49201


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "REST typings apps relevant sections:"
sed -n '230,285p' packages/rest-typings/src/apps/index.ts
echo "--- OperationResult excerpt"
sed -n '190,220p' packages/rest-typings/src/index.ts

echo
echo "useEndpointUploadMutation implementation:"
sed -n '1,90p' apps/meteor/client/hooks/useEndpointUploadMutation.ts

echo
echo "Focused endpoint references for app package upload/update:"
rg -n "POST_API|api\.v1\.post|addRoute\\(['\"]apps|apiServer\\.post|apps/private|private-app|updateApp|installApp|AppClientOrchestrator|AppManager|update\\(|install\\(" apps/meteor/server/api apps/meteor/ee/server/apps apps/meteor/app/apps apps/meteor/client --glob '*.{ts,tsx,js}' | head -400

Repository: RocketChat/Rocket.Chat

Length of output: 18157


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "REST typings apps route list around /apps/update:"
rg -n "/apps(update|private|update-app|updateApp|updateApp.*)|update" packages/rest-typings/src/apps/index.ts packages/rest-typings/src/help* packages/rest-typings/src -g '*.ts' | head -250

echo
echo "Server endpoint files that contain updateApp handler:"
rg -n "updateApp\\(|update\\(.*app|APP|app.*update|API\\.v1\\.post|Router|apps/update|update-app" apps/meteor/ee/server/apps apps/meteor/server/api apps/meteor/app/apps apps/meteor/client --glob '*.{ts,tsx,js,jsx}' | head -400

echo
echo "REST typings index imports listing app route file names:"
rg -n "from '.*/apps|from '../apps|from './apps" packages/rest-typings/src/index.ts packages/rest-typings/src/rest* packages/rest-typings/src/v1 packages/rest-typings/src/app packages/rest-typings/src -g '*.ts' | head -200

Repository: RocketChat/Rocket.Chat

Length of output: 47065


Remove the type-unsafe endpoint casts.

useUpload always returns UploadResult, so useMutation should reject on !result.success and type the app-install/update endpoint result separately instead of widening through as unknown. Also add the update endpoint result type to @rocket.chat/rest-typings so /apps/update can share the same typed response contract as /apps.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx` around lines 43
- 46, Update the useUpload mutation callback in useInstallApp to handle
UploadResult by rejecting when result.success is false and returning the typed
success payload, removing the unknown/type-unsafe casts. Define a separate
app-install/update endpoint result type in `@rocket.chat/rest-typings` and apply
it to the /apps and /apps/update contracts so useMutation receives the correct
typed response.

Source: Coding guidelines

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants