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) => unknown
However, 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 : error
Type 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) => E
Option 2: Widen error field type
// In RxStatefulWithError
error: unknown
Recommendation
Option 1 is preferred as it keeps the error type consistent end-to-end and provides better type safety for consumers.
Acceptance Criteria
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
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
errorMappingFnis typed as:However, the
errorfield inRxStatefulWithErroris typed asE, but the current code casts the result toany:Type Inconsistency
The function returns
unknownbut we expect typeEfor the error field, requiring an unsafe cast.Proposed Solutions
Option 1: Keep error type consistent (Recommended)
Option 2: Widen error field type
Recommendation
Option 1 is preferred as it keeps the error type consistent end-to-end and provides better type safety for consumers.
Acceptance Criteria
as anycast in error handlingerrorMappingFnsignature to returnEtypeImpact
Priority
Medium - Type safety improvement, not a runtime bug
Labels
typescript, type-safety, refactor