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
src/middleware/rate-limit.ts (lines 20, 54, 68, 86) - request as any
src/modules/admin/webhook.service.ts (lines 61, 224, 260, 271) - Untyped parameters
src/services/webhook-dispatcher.ts (line 160, 234) - payload as any, col: any
src/routes/versioning.ts (line 34) - (request as any).apiVersion
src/stellar/transactions.ts (line 28) - (err as any)?.response
src/stellar/client.ts (lines 98, 151, 184, 217, 253) - err: any
src/middleware/response-envelope.ts (line 13) - (request as any).apiVersion
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
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
What
Replace
as anytype assertions throughout the codebase with proper TypeScript types to improve type safety and catch potential runtime errors at compile time.Why
Using
as anydefeats 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
src/middleware/rate-limit.ts(lines 20, 54, 68, 86) -request as anysrc/modules/admin/webhook.service.ts(lines 61, 224, 260, 271) - Untyped parameterssrc/services/webhook-dispatcher.ts(line 160, 234) -payload as any,col: anysrc/routes/versioning.ts(line 34) -(request as any).apiVersionsrc/stellar/transactions.ts(line 28) -(err as any)?.responsesrc/stellar/client.ts(lines 98, 151, 184, 217, 253) -err: anysrc/middleware/response-envelope.ts(line 13) -(request as any).apiVersionsrc/middleware/validation.ts(lines 32, 41) -result.data as anyScope
apiVersion)unknownfor error types and narrow with type guardsAcceptance Criteria
as anycasts remain in the codebaseunknownTechnical Context