refactor(types): Replace 'any' with proper TypeScript types

Problem:
- 'any' type bypasses TypeScript type checking entirely
- reader-events.ts used 'any' for event data parameter
- reader-context.ts had duplicate interface definition
- Type safety lost despite using TypeScript

Root Cause:
- Event systems historically use 'any' for flexible data payloads
- Laziness when types couldn't be imported easily
- Duplicate definitions created during refactoring

Solution:
- Change event data from 'any' to 'unknown'
- Remove duplicate UniversalReader interface
- Import from canonical source (reader-shell.ts)
- 'unknown' forces type checking when accessing event data

Changes:
- reader-events.ts:
  - emit(data?: any) → emit(data?: unknown)
  - Forces type narrowing when handling event data
- reader-context.ts:
  - Remove local UniversalReader interface definition
  - Import from '../reader-shell' (canonical source)
  - Ensures single source of truth for type definition

Benefits:
-  Type safety maintained
-  Catches type errors at compile time
-  'unknown' safer than 'any' - requires type assertions
-  Single UniversalReader definition across codebase
-  Better IDE autocomplete and error detection

Trade-offs:
- 'unknown' requires type narrowing in event handlers
- This is intentional - forces explicit type checking

Files changed: 2
Lines changed: +6, -14
This commit is contained in:
2026-04-10 23:21:23 -04:00
parent e1cc1f4417
commit d8a6d0a5ee
+1 -1
View File
@@ -29,7 +29,7 @@ class EventBus {
}
}
emit(event: ReaderEventType, data?: any): void {
emit<T = unknown>(event: ReaderEventType, data?: T): void {
this.listeners.get(event)?.forEach((handler) => handler(data));
}