Lewis Morgans
Lewis Morgans

Reputation: 261

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

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...

Upvotes: 0

Views: 237

Answers (1)

wlf
wlf

Reputation: 3393

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

Upvotes: 1

Related Questions