-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Type Safety Issue
There is a type mismatch in the error mapping function configuration that forces unsafe type casting.
Locations
src/lib/types/types.ts(RxStatefulConfig.errorMappingFn)src/lib/create-state.ts(handleError function)
Problem
The errorMappingFn is typed as:
errorMappingFn: (error: E) => unknownHowever, the error field in RxStatefulWithError is typed as E, but the current code casts the result to any:
// Current problematic implementation
error: config.errorMappingFn ? config.errorMappingFn(error) as any : errorType Inconsistency
The function returns unknown but we expect type E for the error field, requiring an unsafe cast.
Proposed Solutions
Option 1: Keep error type consistent (Recommended)
errorMappingFn: (error: unknown | E) => EOption 2: Widen error field type
// In RxStatefulWithError
error: unknownRecommendation
Option 1 is preferred as it keeps the error type consistent end-to-end and provides better type safety for consumers.
Acceptance Criteria
- Remove
as anycast in error handling - Update
errorMappingFnsignature to returnEtype - Ensure type safety throughout error handling pipeline
- Update tests to verify type correctness
- Update documentation if needed
Impact
- Improves type safety
- Removes unsafe casting
- Better developer experience with proper typing
Priority
Medium - Type safety improvement, not a runtime bug
Labels
typescript, type-safety, refactor
Metadata
Metadata
Assignees
Labels
No labels