From af839d40060941ac95304e9bd021a83ed52740bf Mon Sep 17 00:00:00 2001 From: Mac Mini Date: Tue, 16 Sep 2025 08:21:46 +0200 Subject: [PATCH] fix: remove unsafe type casting in errorMappingFn - Changed errorMappingFn return type from unknown to E for type consistency - Removed unsafe 'as any' cast in handleError function - Maintains type safety throughout error handling pipeline Fixes #46 --- libs/rx-stateful/src/lib/create-state.ts | 2 +- libs/rx-stateful/src/lib/types/types.ts | 30 +++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/rx-stateful/src/lib/create-state.ts b/libs/rx-stateful/src/lib/create-state.ts index 7e4a028..52d4288 100644 --- a/libs/rx-stateful/src/lib/create-state.ts +++ b/libs/rx-stateful/src/lib/create-state.ts @@ -194,7 +194,7 @@ function handleError( error$$: Subject> ) { mergedConfig?.beforeHandleErrorFn?.(error); - const errorMappingFn = mergedConfig.errorMappingFn ?? ((error: E) => error as any); + const errorMappingFn = mergedConfig.errorMappingFn ?? ((error: E) => error); error$$.next({ error: errorMappingFn(error), context: 'error', isLoading: false, isRefreshing: false, value: null }); return NEVER; } diff --git a/libs/rx-stateful/src/lib/types/types.ts b/libs/rx-stateful/src/lib/types/types.ts index 61d628b..7d3e84f 100644 --- a/libs/rx-stateful/src/lib/types/types.ts +++ b/libs/rx-stateful/src/lib/types/types.ts @@ -1,9 +1,7 @@ -import {Observable, Subject} from 'rxjs'; -import {RxStatefulAccumulationFn} from "./accumulation-fn"; -import {RefetchStrategy} from "../refetch-strategies/refetch-strategy"; -import {Injector} from "@angular/core"; - - +import { Observable, Subject } from 'rxjs'; +import { RxStatefulAccumulationFn } from './accumulation-fn'; +import { RefetchStrategy } from '../refetch-strategies/refetch-strategy'; +import { Injector } from '@angular/core'; /** * @publicApi @@ -11,9 +9,7 @@ import {Injector} from "@angular/core"; * @description * Context of the current emission. */ -export type RxStatefulContext = 'suspense' | 'error' | 'next'; - - +export type RxStatefulContext = 'suspense' | 'error' | 'next'; /** * @publicApi @@ -30,8 +26,10 @@ export interface RxStateful { hasValue: boolean; } - -export type RxStatefulWithError = Pick, 'error' | 'context' | 'isLoading' | 'isRefreshing' | 'value' >; +export type RxStatefulWithError = Pick< + InternalRxState, + 'error' | 'context' | 'isLoading' | 'isRefreshing' | 'value' +>; /** * @internal @@ -57,7 +55,7 @@ export interface RxStatefulConfig { /** * One or multiple Trigger to refresh the source$. */ - refetchStrategies?: RefetchStrategy[] | RefetchStrategy + refetchStrategies?: RefetchStrategy[] | RefetchStrategy; /** * Define if the value should be kept on refresh or reset to null * @default false @@ -78,7 +76,7 @@ export interface RxStatefulConfig { * Mapping function to map the error to a specific value. * @param error - the error which is thrown by the source$, e.g. a {@link HttpErrorResponse}. */ - errorMappingFn?: (error: E) => unknown; + errorMappingFn?: (error: E) => E; /** * Function which is called before the error is handled. * @param error - the error which is thrown by the source$, e.g. a {@link HttpErrorResponse}. @@ -107,12 +105,12 @@ export interface SourceTriggerConfig { operator?: 'switch' | 'merge' | 'concat' | 'exhaust'; } -export type RxStatefulSourceTriggerConfig = RxStatefulConfig &{ +export type RxStatefulSourceTriggerConfig = RxStatefulConfig & { /** * */ - sourceTriggerConfig: SourceTriggerConfig -} + sourceTriggerConfig: SourceTriggerConfig; +}; /** * @publicApi