Skip to content

[Improvement] Fix type safety issues — eliminate and unsafe casts #190

@d-oit

Description

@d-oit

Description

The codebase has several type safety violations despite the project rule "Use strict TypeScript. Do not use any":

as any Usage

File Line Usage
src/db/repository.ts 116 (rows[0] as any).rowid
src/db/repository.ts 294 (rows[0] as any).rowid

as unknown as Double Casts

File Line Usage
src/lib/search.ts 169 e.rowid as unknown as number
src/lib/search.ts 178 c.rowid as unknown as number
src/features/mindmap/MindMapView.tsx 103 MindElixir as unknown as new (...)
src/lib/perf/components.tsx 15 (perf as unknown as { _entries: ... })._entries

File-level ESLint Disables

File Line Disabled Rules
cli/index.ts 1 5 @typescript-eslint/no-unsafe-* rules
cli/db.ts 1 @typescript-eslint/no-unsafe-return

Other Issues

  • src/db/repository.ts:253: z.array(z.unknown()).parse(results) as Array<Record<string, unknown>>
  • src/db/repository.ts:741: rows.map(r => r as GraphSnapshot) — unsafe cast in listSnapshots
  • src/lib/search.ts:206: (r as { type: string }).type — type assertion on RankedResult

Recommended Fix

  1. Define proper SQLite row types with rowid included
  2. Use Zod schemas to parse raw rows instead of casting
  3. Fix MindElixir type declarations properly (create a .d.ts file)
  4. Remove file-level eslint-disable — fix each instance individually
  5. Use z.infer<typeof Schema> consistently

Acceptance Criteria

  • No as any in production code
  • No as unknown as double casts
  • No file-level eslint-disable for TypeScript safety rules
  • All row types include rowid
  • Proper .d.ts for MindElixir

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: backendBackend/data layerduplicateThis issue or pull request already existsimprovementImprovement to existing featurepriority: highHigh prioritytech-debtTechnical debt

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions