How to declare type in NGRX Effect V10? Classes no longer used so Type not inferred

221 Views Asked by At

So since the V10 upgrade to NGRX you can no longer pass in a type of Action to the effect, as Actions are now declared as functions isntead of classes. Is there still a way to handle this in V10?

export const myAction = createAction(
    '[myAction]',
    props<{person: User}> ()
);

@Effect({ dispatch: false })
    x = this.actions$.pipe(
        ofType**<myAction>**('[myAction]'),

I don't have access to person prop. Where in before version 10 you did because it was a class...

1

There are 1 best solutions below

3
On BEST ANSWER

See https://ngrx.io/guide/effects#incorporating-state

  1. Pass myAction directly to ofType
  2. The action is typed according to its props, so you can just use action.person
@Effect({ dispatch: false })
  x = this.actions$.pipe(
    ofType(myAction),
    map(action => of(action.person))
  );

Also it would be preferable to use the new createEffect syntax.

Stackblitz: https://stackblitz.com/edit/so-ngrx-oftype?file=index.ts