From cbdcfba8acf4f40782c160592ddd16f9af751867 Mon Sep 17 00:00:00 2001 From: Gabriel Guerrero Date: Tue, 19 Mar 2024 12:41:17 +0000 Subject: [PATCH] test(asyn-traits): fix test after migration to angular v15 and ngrx 15 BREAKING CHANGE: requires angular 15 and ngrx 15 --- .../lib/async-action/async-action.trait.ts | 52 +++++++------------ 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/libs/ngrx-traits/common/src/lib/async-action/async-action.trait.ts b/libs/ngrx-traits/common/src/lib/async-action/async-action.trait.ts index ebc0f0b5..235342c4 100644 --- a/libs/ngrx-traits/common/src/lib/async-action/async-action.trait.ts +++ b/libs/ngrx-traits/common/src/lib/async-action/async-action.trait.ts @@ -125,16 +125,11 @@ export function addAsyncActionTrait< `${actionsGroupKey} ${nameAsSentence} Failure` )) as ActionCreatorWithOptionalProps, }; - //TypeScript error after migration to 4.9.5 - //Removed because 'name' is not optional - //if (name) { - return { - [`${name}`]: internalActions.request, - [`${name}Success`]: internalActions.requestSuccess, - [`${name}Fail`]: internalActions.requestFail, - } as AsyncActionActions; - //} - //return internalActions; + return { + [`${name}`]: internalActions.request, + [`${name}Success`]: internalActions.requestSuccess, + [`${name}Fail`]: internalActions.requestFail, + } as AsyncActionActions; }, selectors: () => { function isLoadingEntity>(state: S) { @@ -160,32 +155,21 @@ export function addAsyncActionTrait< // Added 'any' to 'state' and removed 'as AsyncActionState' // because OnReducer have a weird type for the state. // TODO: Investigate if possible to remove the 'any' type and have better type safety + // tried remove the any seems to be a problex with ngrx on making the state unknown return createReducer( initialState, - on( - internalActions.request, - (state:any) => - ({ - ...state, - [`${name}Status`]: 'loading', - } )// as AsyncActionState) - ), - on( - internalActions.requestFail, - (state:any) => - ({ - ...state, - [`${name}Status`]: 'fail', - })// as AsyncActionState) - ), - on( - internalActions.requestSuccess, - (state:any) => - ({ - ...state, - [`${name}Status`]: 'success', - }) //as AsyncActionState) - ) + on(internalActions.request, (state: any) => ({ + ...state, + [`${name}Status`]: 'loading', + })), + on(internalActions.requestFail, (state: any) => ({ + ...state, + [`${name}Status`]: 'fail', + })), + on(internalActions.requestSuccess, (state: any) => ({ + ...state, + [`${name}Status`]: 'success', + })) ); }, });