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