我在 Angular 2 和 ngrx/store1 或 2 中开发了 Angular 应用程序(我没有 package.json 或 node_moduels)。我正在尝试在 Angular 5 和 ngrx/store 5.1.0 中设置该应用程序。正如预期的那样,有些东西在最近的版本中不可用。这不起作用的一个关键是 Action 没有有效负载。如果我用有效负载实例化操作,它会返回“错误 TS2339:类型‘操作’上不存在属性‘有效负载’;”我按照ngrx/store库中的Action代码,实际上,Action接口(interface)定义如下。
export interface Action {
type: string;
}
我在互联网上搜索了很多有关新 ngrx/store 的信息,但是我找不到答案,有人有关于它的信息吗?
最佳答案
实际上它已从新版本的 ngrx/store
中删除。但您可以通过一些方法自行部署。检查this github issue ,人们提出了不同的有用的解决方案。
话虽这么说,我最喜欢的解决方案是将 Action
接口(interface)扩展为一个新的通用接口(interface),如下所示:
export interface NewAction<T> extends Action {
type: string;
payload: T;
}
然后你可以像这样使用它:
ExampleAction: NewAction<boolean> = {
type: 'myType',
payload: true
};
关于angular - 操作在 @ngrx/store 中没有有效负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48912165/