Skip to content

fix: replace 'any' types with proper TypeScript types (fixes #1265)#1269

Open
Harshit2405-2004 wants to merge 1 commit intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1265-type-safety-clean
Open

fix: replace 'any' types with proper TypeScript types (fixes #1265)#1269
Harshit2405-2004 wants to merge 1 commit intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1265-type-safety-clean

Conversation

@Harshit2405-2004
Copy link
Copy Markdown

TYPE SAFETY FIX - Phase 1: Critical Paths

Issue: #1265

Problem:
Widespread use of 'any' type across codebase (30+ occurrences) causing:

  • No IDE autocomplete or type checking
  • Runtime errors not caught at compile time
  • Refactoring breaks silently
  • Difficult to trace data flow
  • Production runtime errors

Phase 1 Changes (Critical Paths):
This commit addresses the most critical type safety issues in core authentication and API packages.

New Type Definitions:

  • packages/api/src/types.ts - Message, User, ActionData, UiInteractionData
  • packages/auth/src/types.ts - CurrentUser, AuthToken

Fixed Files:

  • packages/api/src/cloneArray.ts • Use generic type <T extends Record<string, unknown>> • Properly typed cloning function

  • packages/api/src/EmbeddedChatApi.ts • onMessageCallbacks: Message type instead of any • onActionTriggeredCallbacks: ActionData instead of any • onUiInteractionCallbacks: UiInteractionData instead of any

  • packages/auth/src/RocketChatAuth.ts • currentUser: CurrentUser | null instead of any • authListeners: Properly typed callbacks

  • packages/auth/src/Api.ts • request() data parameter: unknown instead of any • ApiError constructor: unknown[] instead of any[]

  • packages/rc-app/lib/getCallbackContent.ts • config: CallbackConfig interface instead of any • error parameter: optional string type

Exported Types:

  • packages/api/src/index.ts - Export all types
  • packages/auth/src/index.ts - Export all types

Impact:
✅ Type safety in critical authentication paths
✅ IDE autocomplete for message callbacks
✅ Compile-time error detection
✅ Better refactoring support
✅ Clearer data flow

Next Phase:

  • Remaining packages (24+ files)
  • Additional interfaces for complex types
  • Stricter tsconfig settings

Brief Title

Acceptance Criteria fulfillment

  • Task 1
  • Task 2
  • Task 3

Fixes # (issue)

Video/Screenshots

PR Test Details

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-<pr_number> after approval. Contributors are requested to replace <pr_number> with the actual PR number.

…at#1265)

TYPE SAFETY FIX - Phase 1: Critical Paths

Issue: RocketChat#1265

Problem:
Widespread use of 'any' type across codebase (30+ occurrences) causing:
- No IDE autocomplete or type checking
- Runtime errors not caught at compile time
- Refactoring breaks silently
- Difficult to trace data flow
- Production runtime errors

Phase 1 Changes (Critical Paths):
This commit addresses the most critical type safety issues in core
authentication and API packages.

New Type Definitions:
- packages/api/src/types.ts - Message, User, ActionData, UiInteractionData
- packages/auth/src/types.ts - CurrentUser, AuthToken

Fixed Files:
- packages/api/src/cloneArray.ts
  • Use generic type <T extends Record<string, unknown>>
  • Properly typed cloning function

- packages/api/src/EmbeddedChatApi.ts
  • onMessageCallbacks: Message type instead of any
  • onActionTriggeredCallbacks: ActionData instead of any
  • onUiInteractionCallbacks: UiInteractionData instead of any

- packages/auth/src/RocketChatAuth.ts
  • currentUser: CurrentUser | null instead of any
  • authListeners: Properly typed callbacks

- packages/auth/src/Api.ts
  • request() data parameter: unknown instead of any
  • ApiError constructor: unknown[] instead of any[]

- packages/rc-app/lib/getCallbackContent.ts
  • config: CallbackConfig interface instead of any
  • error parameter: optional string type

Exported Types:
- packages/api/src/index.ts - Export all types
- packages/auth/src/index.ts - Export all types

Impact:
✅ Type safety in critical authentication paths
✅ IDE autocomplete for message callbacks
✅ Compile-time error detection
✅ Better refactoring support
✅ Clearer data flow

Next Phase:
- Remaining packages (24+ files)
- Additional interfaces for complex types
- Stricter tsconfig settings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant