1
votes

I don't understand how to avoid such error NGRX TypeError: Actions must have a type property. Please help to find out what is wrong.

I have two actions,

export class UpdateWordListAction implements Action {
    static readonly TYPE: 'UPDATE_WORD_LIST';
    readonly type: "UPDATE_WORD_LIST";
    constructor() {};
}
export class WordListLoadedSuccessAction implements Action {
    readonly words: Word[];
    static readonly TYPE: 'WORD_LIST_LOADED_SUCCESS';
    readonly type: "WORD_LIST_LOADED_SUCCESS";
    constructor(words: Word[]) {};
}

One effect,

@Injectable()
export class MyEffects {
 
     testEffect$ = createEffect(() => 
      this.actions$.pipe(
        ofType(UpdateWordListAction.TYPE),
        switchMap(() => this.wordService.getWordList()),
        map(words => new WordListLoadedSuccessAction(words)),
        catchError(() => EMPTY)));
 
  constructor(
    private actions$: Actions,
    private wordService: WordService
  ) {}
}

And such client

this.store.dispatch(new UpdateWordListAction());
1

1 Answers

2
votes

You need to use assign sign instead of colon. Try this:

    export class UpdateWordListAction implements Action {
       readonly type = "UPDATE_WORD_LIST";
       constructor() {};
    }