Skip to content

refactor(convex): remove unnecessary as type assertions #94

@larryro

Description

@larryro

Problem Statement

The Convex directory contains approximately 900+ as type assertions that bypass TypeScript's type system. This violates the project guidelines: "DO NOT use type casting. Avoid any, and unknown whenever possible."

Many of these assertions are unnecessary and can be replaced with proper type annotations following Convex best practices.

Current State

Type assertions are used in several problematic patterns:

  1. Better Auth Integration - Returns any types, causing cascading assertions
  2. Schema fields via as any - Accessing existing schema fields unnecessarily
  3. External API responses - Untyped JSON responses (RAG, IMAP)
  4. Metadata field access - Repeated casts for same structure
  5. Handler return types - Missing explicit type annotations

Proposed Solution

Replace type assertions with proper TypeScript typing:

  1. Create typed interfaces for Better Auth adapter responses
  2. Create typed interfaces for external API responses (RAG, IMAP, etc.)
  3. Create document metadata type definitions
  4. Add explicit return type annotations to Convex handlers
  5. Use direct property access instead of as any casts for schema-defined fields

Affected Components

  • convex/member.ts - Better Auth member operations
  • convex/documents.ts - Document management
  • convex/model/documents/transform_to_document_item.ts - Document transformation
  • convex/workflow/actions/rag/helpers/upload_file_direct.ts - RAG upload
  • convex/workflow/actions/rag/helpers/get_document_info.ts - RAG info
  • convex/workflow/actions/imap/helpers/get_imap_credentials.ts - IMAP credentials
  • convex/model/conversations/transform_conversation.ts - Conversation transformation
  • convex/workflow_assistant_agent.ts - Workflow agent
  • ~40-50 other Convex files

Acceptance Criteria

  • All as any casts removed (except where strictly necessary)
  • Better Auth response types defined and used
  • RAG API response types defined and used
  • Document metadata types defined and used
  • All Convex handlers have explicit return type annotations
  • TypeScript compiles without errors (npx convex dev --once)
  • Build succeeds (npm run build)

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions