Skip to content

Fix excessive 'as any' type casts bypassing type safety #29

@mchestr

Description

@mchestr

Problem

Multiple files use as any type casts to bypass TypeScript's type checking, defeating the purpose of strict mode enabled in the project.

Files affected:

  • actions/maintenance.ts:75, 108 - criteria: validated.criteria as any
  • lib/maintenance/scanner.ts:230 - const criteria = rule.criteria as any
  • lib/maintenance/rule-evaluator.ts:219 - return (item as any)[fieldKey]

Root cause: Prisma's JSON type doesn't recognize Zod's validated types, leading developers to use as any as a workaround.

Impact

  • Type safety violations could cause runtime errors
  • Defeats TypeScript strict mode guarantees
  • Could access undefined properties without compile-time warnings
  • Makes refactoring more dangerous

Solution

Replace as any casts with proper type assertions:

For Prisma JSON fields

// ❌ Wrong
criteria: validated.criteria as any

// ✅ Correct
criteria: validated.criteria as Prisma.JsonValue

For dynamic property access

// ❌ Wrong
return (item as any)[fieldKey]

// ✅ Correct
return (item as Record<string, unknown>)[fieldKey]

Files to Fix

  1. actions/maintenance.ts - Lines 75, 108
  2. lib/maintenance/scanner.ts - Line 230
  3. lib/maintenance/rule-evaluator.ts - Line 219

Acceptance Criteria

  • All as any casts replaced with proper types
  • TypeScript compilation passes with no errors
  • All existing tests still pass
  • No new type errors introduced

Reference

  • CLAUDE.md: TypeScript strict mode enabled with all checks
  • Project uses TypeScript strict mode: noUnusedLocals, noUnusedParameters, noImplicitReturns

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrefactorCode refactoring and technical debt

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions