在角度ngrx存储项目中,'action;和'action'的参数类型不兼容 [英] Types of parameters 'action' and 'action' are incompatible in angular ngrx store project

查看:20
本文介绍了在角度ngrx存储项目中,'action;和'action'的参数类型不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用角度创建我的第一个NGRX项目,并遵循tutorial(请在此处找到所有文件代码)。

当我在app.mdole.ts中声明缩减器时,我面临此编译错误。

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
    })
  ],

推荐答案

如果要修复此问题,只需在ngrx的常规操作中更改函数中的TutorialAction。然后将函数内的一个常量声明为TutorialAction,如下所示:

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

     switch(tutorialAction .type) { .. }

}

让我知道它是否起作用

这篇关于在角度ngrx存储项目中,&#39;action;和&#39;action&#39;的参数类型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆