Skip to content

Reduce excessive any type usage in ChatInterface.tsx #80

@KaranJagtiani

Description

@KaranJagtiani

The ChatInterface.tsx component uses any type casts extensively (~30+ instances), which bypasses TypeScript's type safety and can hide bugs. Examples include:

const mapTokenUsage = (raw: any): TokenUsage | undefined => { ... }
(lastMessage as any).segments?.length
(s as any).toolExecution
msgs.map((m: any) => { ... })

Scope

UI (ui/src/components/chat/ChatInterface.tsx):

  • Audit all any type usages and replace with proper types.
  • Create or extend interfaces in ui/src/types/chat.ts as needed.
  • For truly dynamic data (e.g., SSE event payloads), use type guards or runtime validation instead of any casts.
  • Focus on the most impactful areas first: message segment handling, tool execution state, and SSE event mapping.

UI (ui/src/types/chat.ts, ui/src/types/events.ts):

  • Define proper interfaces for message segments, tool executions, and event payloads.
  • Replace annotations?: any with a proper interface.

Acceptance criteria

  • Reduce any usage in ChatInterface.tsx completely.
  • No TypeScript errors introduced.
  • Type guards are used for runtime validation.
  • Chat functionality remains unchanged.

How to test manually

  1. Run yarn build in the UI directory. There should be no type errors.
  2. Run the UI locally (see ui/README.md) and test all chat flows:
    • Sending messages
    • Tool execution and approval
    • Streaming responses
    • Loading chat history
  3. Verify no runtime errors in the browser console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions