You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The actionCreatorVoid helper method has a 'test' method that acts as a type guard, allowing typescript to deduce the type is 'IAction'.
Modern versions of typescript use this type information to narrow the remaining type, so you can easily end up with compilation errors in your reducers
// problematicActions.tsexportconststringPayloadAction=actionCreator<string>('STRING_PAYLOAD');exportconstnoPayloadAction1=actionCreatorVoid('NO_PAYLOAD_1');exportconstnoPayloadAction2=actionCreatorVoid('NO_PAYLOAD_2');// problematicReducer.tsexporttypeTState={}exportfunctionproblematicReducer(state: Tstate={},action: IAction): TState{if(stringPayloadAction.test(action)){// OK: action deduced as IAction<string>}elseif(noPayloadAction1.test(action)){// OK: action deduced as IAction}elseif(noPayloadAction2.test(action)){// Error: Typescript deduces action as 'never' within this check// as the previous noPayloadAction1 check covered all IAction cases.}returnstate;}
The solution is to change the test methods in helper.ts to return boolean rather than act as type guards.
The text was updated successfully, but these errors were encountered:
The actionCreatorVoid helper method has a 'test' method that acts as a type guard, allowing typescript to deduce the type is 'IAction'.
Modern versions of typescript use this type information to narrow the remaining type, so you can easily end up with compilation errors in your reducers
The solution is to change the test methods in helper.ts to return boolean rather than act as type guards.
The text was updated successfully, but these errors were encountered: