1

Angular 6 project fails to compile in prod with aot turned on.

I know I'm supposed to turn the function expression into an exported function but with what's going on I can't get it done correctly. I looked around for people with a similar problem but wasn't helped by them. I think my instance is a bit more intense.

The Problem File

export const createReducer = <T>(type: string) => () => {
    return <T>(state = createInitialState<T>(), action: any): IState<T> => {
        switch (action.type) {
            case `CLEARCACHE_${type}`: {
                return state = createInitialState();
            }
            case `CREATE_${type}`: {
                return incrementLoading(state);
            }
            ... Other cases.
        }
    }
}

The Caller of the problem file

export const reducers = {
    company: (createReducer(getStoreKey(Company)))(),
    mortgages: (createReducer(getStoreKey(Mortgage)))(),
    ... More of the same.
}

I can't wrap my tiny brain around what's actually happening and how to reverse engineer it appropriately.

Let me know if you need more code or info.

Here's the full error.

ERROR in src\app\data\store\store.module.ts(14,27): Error during template compile of 'StoreModule'
    Function expressions are not supported in decorators in 'reducers'
        'reducers' references 'createReducer' at src\app\data\store\reducers\index.ts(13,15)
            'createReducer' contains the error at src\app\data\store\reducers\generic.reducer.ts(53,30)
    Consider changing the function expression into an exported function.

0 Answers0