本文介绍了Angular2 AoT-不支持表达形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use ngc to compile 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导出常量.

It looks like it is complaining about how i'm exporting a constant for @ngrx/store.

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

I tried changing the constant into an exported function... as well as all of the properties.

以前:

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;
};

我在我的import []中使用了它,例如:

I'm using this in my imports[] as such:

...
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声明更改为导出函数

Each reducer has already been changed from a constant lambda declaration to an exported function

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

export function reducer() { ... }

任何人都可以理解ngc编译器在抱怨什么吗?

Can anyone make sense of what the ngc compiler is complaining about?

推荐答案

在此特定实例中,一旦我将原始常量声明修改为不使用"... as IAppState"子句,ngc编译就停止抱怨.

In this specific instance, the ngc compliation stopped complaining once I modified the original constant declaration to not us the "... as IAppState" clause.

不起作用:

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
    };

这篇关于Angular2 AoT-不支持表达形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:46