angular-architects / ngrx-toolkit

Various Extensions for the NgRx Signal Store
MIT License
146 stars 22 forks source link

Action payload types are resolved to 'never' inside reducer #14

Closed giniedp closed 7 months ago

giniedp commented 7 months ago

I was trying out the library and am hitting a type resolution error on the following example

https://stackblitz.com/edit/stackblitz-starters-unmh93?file=src%2Fapp.store.ts

import { payload, withRedux } from '@angular-architects/ngrx-toolkit';
import { patchState, signalStore, withState } from '@ngrx/signals';
export interface Flight {
  id: string;
}
export const FlightStore = signalStore(
  { providedIn: 'root' },
  withState({ flights: [] as Flight[] }),
  withRedux({
    actions: {
      public: {
        load: payload<{ from: string; to: string }>(),
      },
      private: {
        loaded: payload<{ flights: Flight[] }>(),
      },
    },
    reducer(actions, on) {
      on(actions.loaded, ({ flights }, state) => {
        for (const flight of flights) { // <-- error: Type never must have an iterator ...
          console.log(flight);
        }
        patchState(state, { flights });
      });
    },
    effects(actions, create) {
      return {};
    },
  })
);

Is there anything i am missing maybe?

Very excited about the library and can't wait to use it in production.

rainerhahnekamp commented 7 months ago

Thanks for reporting. I can confirm it. Expect a fix soon.

rainerhahnekamp commented 7 months ago

Fixed in #15

rainerhahnekamp commented 7 months ago

@giniedp the fix has been integrated into 0.0.7. Please not, that the reducers' on function got a change as well. The parameters of the function have been changed. First parameter is the state and the second the action.

Thanks for reporting this bug.