打字稿:重写一个胖箭头功能不丢失裸功能签名检查

Typescript: rewrite a fat arrow function a do not lose bare function signature check

为了在 Angular 中使用 AOT,我需要重写我所有的函数/reducer 以不使用箭头函数:

ERROR in Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function

Reducer 使用 ES6 风格:

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> 不再指定。如何指定configreducerimplementsActionReducer<ConfigModel>? 是否可以指定该函数用裸函数实现可调用接口?

ActionReducer(为了完整起见):

export interface ActionReducer<T, V extends Action = Action> {
    (state: T | undefined, action: V): T;
}

将箭头函数重写为导出函数不会阻止您在导出中分配变量:

export const config: ActionReducer<ConfigModel> = function(state: ConfigModel = null, {type, payload}: action.ResponseActions) {
    switch (type) {
        case configAction.LOAD_SUCCESS:
            return ...;
        default:
            return state;
    }
};