Skip to content

Fix unused code, array mutation bug, and TypeScript errors #290

Description

@aadityakumarsah

Description

This issue addresses several bugs, code smells, and TypeScript errors discovered during static analysis (linting and type checking).

1. Unused Imports in Test Files

  • File: apps/web/lib/chat-agent-registry.test.ts
  • Issue: The imports existsSync and mkdirSync from node:fs are declared but never used in the file, cluttering the import block.

2. Dead Code (Unused Function and Variable)

  • File: apps/web/lib/denchclaw-state.ts
  • Issue: The function defaultEmailBodyHydrationAttempted is defined but never invoked anywhere in the codebase.
  • File: apps/web/lib/active-runs.ts
  • Issue: The variable everSentResponseActivity is declared and assigned values in the wireSubscribeOnlyProcess function, but it is never used in that scope.

3. Array Mutation Bug

  • File: apps/web/lib/denchclaw-state.ts
  • Issue: The code uses Array.from(current).sort(). The sort() method mutates the array in place. While Array.from creates a new array, using .toSorted() is the more modern, idiomatic, and safer approach to ensure arrays are sorted without unintended side effects (as flagged by eslint-plugin-unicorn(no-array-sort)).

4. TypeScript Error in AI Gateway

  • File: extensions/dench-ai-gateway/sync-trigger.ts
  • Issue: There is a TypeScript error: Element implicitly has an 'any' type because expression of type '"syncTrigger"' can't be used to index type '{}'. This occurs because pluginConfig?.config is not properly typed before attempting to access the ["syncTrigger"] property.

5. Arrow Function Body Formatting and Object Spreads

  • File: apps/web/lib/active-runs.test.ts
  • Issue: The linter flags single-line arrow function bodies (e.g. subscribeToRun(idA, (e) => { if (e) eventsA.push(e); }, { replay: false });) that lack curly braces after the if statement.
  • File: apps/web/lib/active-runs.ts
  • Issue: The linter flags a useless fallback in an object spread (...(details ?? {}) where details is already an object).

Proposed Solution

  • Remove the unused imports from chat-agent-registry.test.ts.
  • Delete the unused defaultEmailBodyHydrationAttempted function from denchclaw-state.ts and the everSentResponseActivity variable from active-runs.ts.
  • Replace .sort() with .toSorted() in denchclaw-state.ts.
  • Add proper type assertion (as Record<string, unknown>) when accessing the config in sync-trigger.ts to satisfy the TypeScript compiler.
  • Add curly braces to the arrow function bodies in active-runs.test.ts.
  • Remove the unnecessary ?? {} fallback in the object spread in active-runs.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions