Typescript 存在枚举类型问题的Ngrx操作
嘿,我正在尝试构建操作/简化程序/等等,但是我遇到了一个令人沮丧的类型脚本问题。我正在尝试对操作类型使用字符串枚举,但无法使用以下内容进行编译: 代码如下:Typescript 存在枚举类型问题的Ngrx操作,typescript,ngrx,ngrx-store,Typescript,Ngrx,Ngrx Store,嘿,我正在尝试构建操作/简化程序/等等,但是我遇到了一个令人沮丧的类型脚本问题。我正在尝试对操作类型使用字符串枚举,但无法使用以下内容进行编译: 代码如下: import { Action, ActionReducerMap } from '@ngrx/store'; export enum AnnoSetsTypes { ADD_MANY = '[AnnoSets] Add Many', RESET = '[AnnoSets] Reset', } export class Add
import { Action, ActionReducerMap } from '@ngrx/store';
export enum AnnoSetsTypes {
ADD_MANY = '[AnnoSets] Add Many',
RESET = '[AnnoSets] Reset',
}
export class AddMany implements Action {
readonly type = AnnoSetsTypes.ADD_MANY;
constructor(public annoSets: any[]) { }
}
export class Reset implements Action {
readonly type = AnnoSetsTypes.RESET;
}
export type AnnoSetsAction = AddMany | Reset;
export interface IAnnoSetsState {
annoSets: any[];
}
export function annoSetsReducer(
state: IAnnoSetsState = { annoSets: [] },
action: AnnoSetsAction
): IAnnoSetsState {
switch (action.type) {
case AnnoSetsTypes.ADD_MANY:
return { annoSets: [...action.annoSets] };
case AnnoSetsTypes.RESET:
return { annoSets: [] };
default:
return state;
}
}
export interface State {
annoSets: IAnnoSetsState;
}
export const reducers: ActionReducerMap<State> = { // <-- COMPILE ERROR HERE
annoSets: annoSetsReducer,
};
从'@ngrx/store'导入{Action,ActionReducerMap};
导出枚举AnnoSetsTypes{
ADD_MANY='[AnnoSets]ADD MANY',
重置=“[AnnoSets]重置”,
}
导出类AddMany实现操作{
只读类型=annosetstTypes.ADD\u MANY;
构造函数(公共注释集:any[]){}
}
导出类重置实现操作{
只读类型=annosetstTypes.RESET;
}
导出类型AnnoSetsAction=AddMany | Reset;
导出接口IANOsetState{
注释集:任何[];
}
导出函数annoSetsReducer(
state:iannosetstate={annoSets:[]},
操作:AnnoSetsAction
):IanosetState{
开关(动作类型){
case AnnoSetsTypes.ADD_MANY:
返回{annoSets:[…action.annoSets]};
案例annosetstTypes.RESET:
返回{annoSets:[]};
违约:
返回状态;
}
}
导出接口状态{
注释集:IANNosetState;
}
export const reducers:ActionReducerMap={/在tsconfig.json
中,设置strict:true
也会设置strictFunctionTypes:true
,这会导致错误。显式禁用strictFunctionTypes
会将其清除。
{
“编译器选项”:{
“源地图”:正确,
“声明”:虚假,
“moduleResolution”:“节点”,
“emit decoromentadata”:正确,
“实验生态学者”:没错,
“lib”:[
“es2017”,
“dom”
],
“目标”:“es5”,
“模块”:“es2015”,
“严格”:是的,
“strictFunctionTypes”:false
},
“compileOnSave”:真
}
似乎在2.6中引入了strictFunctionTypes
,这导致了我的困惑。