Angular2 AoT - Expression form not supported

这一生的挚爱 提交于 2019-12-23 12:27:26

问题


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...

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.

Previously:

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;

Presently:

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

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

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

old

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

new

export function reducer() { ... }

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


回答1:


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

Didn't work:

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;

Worked:

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



回答2:


AoT needs to evaluate some code statically and it currently can't evaluate function content.

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

This might work

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

Just move function calls out and reference a value instead.



来源:https://stackoverflow.com/questions/41795494/angular2-aot-expression-form-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!