Angular2 AoT - 不支持表达形式

时间:2017-01-22 19:57:16

标签: angular ngrx angular2-aot

我试图使用ngc来编译角度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编译器在抱怨什么吗?

2 个答案:

答案 0 :(得分:2)

在这个特定的例子中,一旦我修改原始的常量声明而不是我们的" ...作为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
    };

答案 1 :(得分:0)

AoT需要静态评估某些代码,目前无法评估功能内容。

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),
    ...
],...

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