为了在Angular中使用AOT,我需要重写所有函数/ reducers以不使用箭头函数:
错误中的错误:静态解析符号值时出错。不支持函数调用。考虑使用对导出函数的引用替换函数或lambda
使用ES6风格的Reducer:
export const config: ActionReducer<ConfigModel> = (state: ConfigModel = null, {type, payload}: action.ResponseActions) => {
switch (type) {
case configAction.LOAD_SUCCESS:
return ...;
default:
return state;
}
};
重写为导出的功能样式:
export function config(state: ConfigModel = null, {type, payload}: action.ResponseActions) {
switch (type) {
case configAction.LOAD_SUCCESS:
return ...;
default:
return state;
}
};
但是我丢失了类型检查:带有裸函数签名的可调用接口。
不再指定 ActionReducer<ConfigModel>
。如何指定config
reducer 实现 ActionReducer<ConfigModel>
?
是否可以指定该函数使用裸函数实现可调用接口?
ActionReducer(为了完整起见):
export interface ActionReducer<T, V extends Action = Action> {
(state: T | undefined, action: V): T;
}
答案 0 :(得分:1)
将箭头功能重写为导出的功能并不会阻止您在导出中分配变量:
export const config: ActionReducer<ConfigModel> = function(state: ConfigModel = null, {type, payload}: action.ResponseActions) {
switch (type) {
case configAction.LOAD_SUCCESS:
return ...;
default:
return state;
}
};