Angular2 AoT - 不支持表达形式

Angular2 AoT - Expression form not supported

我正在尝试使用 ngc 编译 angular 2.4.4:

Error: Error encountered resolving symbol values statically. Expression form not supported (position 52:9 in the original .ts file), resolving symbol DEFAULT_APP_STATE in...

它看起来像是在抱怨我如何为@ngrx/store 导出常量。

我尝试将常量更改为导出函数...以及所有属性。

之前:

export const DEFAULT_APP_STATE = {
        Offline: DEFAULT_APP_OFFLINE_STATE,
        Initialized: DEFAULT_APP_INITIALIZED_STATE,
        Console: DEFAULT_CONSOLE_DICTIONARY,
        Identity: DEFAULT_IDENTITY,
        HamburgerState: DEFAULT_HAMBURGER_STATE,
        Customers: DEFAULT_CUSTOMER_STATE,
        UserMenuVisibility: DEFAULT_USER_MENU_VISIBILITY,
        StreamViewMultiple: DEFAULT_STREAM_VIEW_MULTIPLE_STATE,
        StreamViewSingle: DEFAULT_STREAM_VIEW_SINGLE_STATE,
        Streams: DEFAULT_STREAM_DICTIONARY,
        Destinations: DEFAULT_DESTINATION_DICTIONARY,
        DestinationList: DEFAULT_DESTINATION_LIST_STATE,
        IDestinationTranscodeModal: DEFAULT_DESTINATION_TRANSCODE_MODAL_STATE
    } as IAppState;

目前:

export function DEFAULT_APP_STATE() {
    return {
        Offline: DEFAULT_APP_OFFLINE_STATE(),
        Initialized: DEFAULT_APP_INITIALIZED_STATE(),
        Console: DEFAULT_CONSOLE_DICTIONARY(),
        Identity: DEFAULT_IDENTITY(),
        HamburgerState: DEFAULT_HAMBURGER_STATE(),
        Customers: DEFAULT_CUSTOMER_STATE(),
        UserMenuVisibility: DEFAULT_USER_MENU_VISIBILITY(),
        StreamViewMultiple: DEFAULT_STREAM_VIEW_MULTIPLE_STATE(),
        StreamViewSingle: DEFAULT_STREAM_VIEW_SINGLE_STATE(),
        Streams: DEFAULT_STREAM_DICTIONARY(),
        Destinations: DEFAULT_DESTINATION_DICTIONARY(),
        DestinationList: DEFAULT_DESTINATION_LIST_STATE(),
        IDestinationTranscodeModal: DEFAULT_DESTINATION_TRANSCODE_MODAL_STATE()
    } as IAppState;
}; 

我在我的导入中使用它[]:

...
imports: [
    ...,
    StoreModule.provideStore({
                Offline: APP_OFFLINE_REDUCER,
                Initialized: APP_INITIALIZED_REDUCER,
                Console: CONSOLE_REDUCER,
                Identity: IDENTITY_REDUCER,
                Customers: CUSTOMER_REDUCER,
                Hamburger: HAMBURGER_REDUCER,
                UserMenuVisibility: USER_MENU_VISIBILITY_REDUCER,
                StreamViewSingle: STREAM_VIEW_SINGLE_REDUCER,
                StreamViewMultiple: STREAM_VIEW_MULTIPLE_REDUCER,
                Streams: STREAM_REDUCER,
                Destinations: DESTINATION_REDUCER,
                DestinationList: DESTINATION_LIST_REDUCER,
                DestinationTranscodeModal: DESTINATION_TRANSCODE_MODAL_REDUCER
            }, DEFAULT_APP_STATE()),
    ...
],...

每个 reducer 都已经从常量 lambda 声明更改为导出函数

export const reducer = () => { ...} 

export function reducer() { ... }

谁能理解 ngc 编译器在抱怨什么?

A​​oT 需要静态评估一些代码,目前无法评估功能内容。

https://github.com/rangle/angular-2-aot-sandbox#current-status

这可能有效

export const MY_APP_STATE = DEFAULT_APP_STATE();
imports: [
    ...,
    StoreModule.provideStore({
                Offline: APP_OFFLINE_REDUCER,
                Initialized: APP_INITIALIZED_REDUCER,
                Console: CONSOLE_REDUCER,
                Identity: IDENTITY_REDUCER,
                Customers: CUSTOMER_REDUCER,
                Hamburger: HAMBURGER_REDUCER,
                UserMenuVisibility: USER_MENU_VISIBILITY_REDUCER,
                StreamViewSingle: STREAM_VIEW_SINGLE_REDUCER,
                StreamViewMultiple: STREAM_VIEW_MULTIPLE_REDUCER,
                Streams: STREAM_REDUCER,
                Destinations: DESTINATION_REDUCER,
                DestinationList: DESTINATION_LIST_REDUCER,
                DestinationTranscodeModal: DESTINATION_TRANSCODE_MODAL_REDUCER
            }, MY_APP_STATE),
    ...
],...

只需移动函数调用并改为引用一个值。

在此特定实例中,一旦我将原始常量声明修改为不使用“...作为 IAppState”子句,ngc compliation 就会停止抱怨。

没有成功:

export const DEFAULT_APP_STATE = {
        Offline: DEFAULT_APP_OFFLINE_STATE,
        Initialized: DEFAULT_APP_INITIALIZED_STATE,
        Console: DEFAULT_CONSOLE_DICTIONARY,
        Identity: DEFAULT_IDENTITY,
        HamburgerState: DEFAULT_HAMBURGER_STATE,
        Customers: DEFAULT_CUSTOMER_STATE,
        UserMenuVisibility: DEFAULT_USER_MENU_VISIBILITY,
        StreamViewMultiple: DEFAULT_STREAM_VIEW_MULTIPLE_STATE,
        StreamViewSingle: DEFAULT_STREAM_VIEW_SINGLE_STATE,
        Streams: DEFAULT_STREAM_DICTIONARY,
        Destinations: DEFAULT_DESTINATION_DICTIONARY,
        DestinationList: DEFAULT_DESTINATION_LIST_STATE,
        IDestinationTranscodeModal: DEFAULT_DESTINATION_TRANSCODE_MODAL_STATE
    } as IAppState;

工作:

export const DEFAULT_APP_STATE: IAppState = {
        Offline: DEFAULT_APP_OFFLINE_STATE,
        Initialized: DEFAULT_APP_INITIALIZED_STATE,
        Console: DEFAULT_CONSOLE_DICTIONARY,
        Identity: DEFAULT_IDENTITY,
        HamburgerState: DEFAULT_HAMBURGER_STATE,
        Customers: DEFAULT_CUSTOMER_STATE,
        UserMenuVisibility: DEFAULT_USER_MENU_VISIBILITY,
        StreamViewMultiple: DEFAULT_STREAM_VIEW_MULTIPLE_STATE,
        StreamViewSingle: DEFAULT_STREAM_VIEW_SINGLE_STATE,
        Streams: DEFAULT_STREAM_DICTIONARY,
        Destinations: DEFAULT_DESTINATION_DICTIONARY,
        DestinationList: DEFAULT_DESTINATION_LIST_STATE,
        IDestinationTranscodeModal: DEFAULT_DESTINATION_TRANSCODE_MODAL_STATE
    };