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

Bug Fix: TypeScript migration for helpers.ts

Open deepak0x opened this issue 2 months ago • 4 comments

Describe the Bug

The file app/lib/methods/helpers/helpers.ts has @ts-nocheck at the top, which disables TypeScript checking for the entire file. All 8 exported functions lack proper TypeScript type annotations, reducing type safety and developer experience.

Steps to Reproduce

  1. Open app/lib/methods/helpers/helpers.ts
  2. Observe @ts-nocheck - TEMP comment at line 1
  3. Notice all function parameters lack type annotations (e.g., room, sender, item are untyped)
  4. Run yarn lint or TypeScript compiler - no type errors are reported for this file despite missing types

Expected Behavior

  • Remove @ts-nocheck directive
  • Add proper TypeScript types to all function parameters and return types
  • All functions should have complete type annotations
  • TypeScript compiler should properly check this file

Actual Behavior

  • TypeScript checking is disabled for the entire file
  • No type safety for 8 exported functions
  • Potential runtime errors that could be caught at compile time
  • Poor IDE autocomplete and IntelliSense support

Rocket.Chat Server Version

N/A (Code quality issue, not server-dependent)

Rocket.Chat App Version

4.67.0

Device Name

N/A (Code quality issue, not device-specific)

OS Version

N/A (Code quality issue, not OS-specific)

Additional Context

File: app/lib/methods/helpers/helpers.ts

Functions to migrate:

  • isGroupChat(room)
  • getRoomAvatar(room)
  • getUidDirectMessage(room)
  • getRoomTitle(room)
  • getSenderName(sender)
  • canAutoTranslate()
  • isRead(item)
  • hasRole(role)
  • hasPermission(permissions, rid?)

Impact: This file is used in multiple places:

  • app/lib/hooks/useUserData.ts
  • app/containers/MessageComposer/components/ComposerInput.tsx
  • And potentially other files

Related: Part of TypeScript migration effort to improve code quality and maintainability.

deepak0x avatar Nov 10 '25 07:11 deepak0x

@deepakbhagatiitr could you please assign this to me?

ShivaGupta-14 avatar Nov 13 '25 08:11 ShivaGupta-14

@deepakbhagatiitr could you please assign this to me?

No one gets assigned to any specific issue. It you think you can create a fix for this, feel free to open pull request anytime :)

Rohit3523 avatar Nov 13 '25 08:11 Rohit3523

@Rohit3523 Thanks :)

ShivaGupta-14 avatar Nov 13 '25 09:11 ShivaGupta-14

Hi, I've completed the TypeScript migration for helpers.ts and opened PR #6796 to address this issue.

Summary of changes:

  • ✅ Removed @ts-nocheck directive from app/lib/methods/helpers/helpers.ts
  • ✅ Added proper TypeScript types and JSDoc comments to all 8 helper functions
  • ✅ Created TRoomLike type to handle both IRoom and ISubscription objects
  • ✅ Added null checks in calling code to ensure type safety
  • ✅ All TypeScript compilation passes (0 errors in app code)
  • ✅ ESLint passes with no warnings
  • ✅ Metro bundler successfully builds the app

Files modified: 4 files (85 insertions, 40 deletions)

The migration is complete and ready for review. All existing functionality is preserved while improving type safety across the codebase.

DSingh0304 avatar Nov 14 '25 06:11 DSingh0304