Archit Goyal
Archit Goyal

Reputation: 53

Types of parameters 'action' and 'action' are incompatible in angular ngrx store project

I am creating my first NGRX project with angular and following this tutorial(kindly find all files code here).

When I declare the reducers in my app.mdule.ts, I am facing this compilation error.

Type '(state: Tutorial[] | undefined, action: Actions) => Tutorial[]' is not assignable to type 'ActionReducer<Tutorial[], Action>'.
  Types of parameters 'action' and 'action' are incompatible.
    Type 'Action' is not assignable to type 'Actions'.
      Property 'payload' is missing in type 'Action' but required in type 'RemoveTutorial'.
22       **tutorial: reducer**
         ~~~~~~~~
  src/app/actions/tutorial.actions.ts:20:17
    20     constructor(public payload: Tutorial) { }
                       ~~~~~~~~~~~~~~~~~~~~~~~~
    'payload' is declared here.
 imports: [
    BrowserModule,
    AppRoutingModule,
    StoreModule.forRoot({
      tutorial: reducer ///this line is throwing above error
    })
  ],

Upvotes: 3

Views: 2545

Answers (1)

Atlas91
Atlas91

Reputation: 5904

If you want to fix this, just change the TutorialAction in your function in a general Action of ngrx. Then declare a constant inside the funcion as a TutorialAction like this:

export function reducer(state: Tutorial[] = [initialState], action: Action) {
    const tutorialAction = action as TutorialActions.Actions; 

     switch(tutorialAction .type) { .. }

}

Let me know if it works

Upvotes: 5

Related Questions