在angular ngrx道具中没有重载匹配此调用

时间:2020-04-13 09:51:35

标签: javascript angular typescript ngrx

在有角度的应用程序中定义动作和使用道具时,道具上显示“没有重载匹配此调用...”

import { createAction, props } from "@ngrx/store";
export const storeCurrentDashboard = createAction(
  "[effect] store current dashboard in state",
  props<Dashboard>()// here i get the error
);

并且Dashboard类如下所示

export class Dashboard {
  id: number;
  title: string;
  type: DashboardType; // the problem is this property
  blocks?: any[];
}
export enum DashboardType {
  Private = "Private",
  Shared = "Shared",
...
}

并且如果我删除了作为枚举的“ type”属性,一切都会好的。 为什么props的枚举类型有问题?

编译器错误:

   ERROR in ...: error TS2345: Argument of type '"type property is not allowed in action creators"'
 is not assignable to parameter of type 'FunctionWithParametersType<any[], object>'.

1 个答案:

答案 0 :(得分:2)

并且如果我删除了作为枚举的“ type”属性,一切都会好的。为什么props的枚举类型有问题?

是的,type就像NgRx的保留字,在createAction调用中,它与第一个参数匹配。