Skip to content

Replace as any casts with proper TypeScript types #469

Description

@DeFiVC

What

Replace as any type assertions throughout the codebase with proper TypeScript types to improve type safety and catch potential runtime errors at compile time.

Why

Using as any defeats the purpose of TypeScript's type system and can mask bugs. It also makes refactoring harder since the compiler can't verify correctness.

Affected Files

  1. src/middleware/rate-limit.ts (lines 20, 54, 68, 86) - request as any
  2. src/modules/admin/webhook.service.ts (lines 61, 224, 260, 271) - Untyped parameters
  3. src/services/webhook-dispatcher.ts (line 160, 234) - payload as any, col: any
  4. src/routes/versioning.ts (line 34) - (request as any).apiVersion
  5. src/stellar/transactions.ts (line 28) - (err as any)?.response
  6. src/stellar/client.ts (lines 98, 151, 184, 217, 253) - err: any
  7. src/middleware/response-envelope.ts (line 13) - (request as any).apiVersion
  8. src/middleware/validation.ts (lines 32, 41) - result.data as any

Scope

  • Define proper interfaces/types for request objects with additional properties (e.g., apiVersion)
  • Use unknown for error types and narrow with type guards
  • Create proper return type interfaces for webhook stats
  • No functional changes

Acceptance Criteria

  • No as any casts remain in the codebase
  • TypeScript compilation succeeds with strict mode
  • Error handling properly narrows types before accessing properties
  • All type assertions use more specific types or unknown

Technical Context

  • The codebase uses Fastify with TypeScript
  • Error types from Stellar SDK and HTTP calls need proper typing
  • Request augmentation should use module augmentation or proper interfaces

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions