类型typeof app.module上不存在属性

时间:2016-10-10 16:13:20

标签: angular ngrx ng-modules

import { StoreModule } from "@ngrx/store";
import { currentPurchase } from "../shared/index";

@NgModule({
 imports: [
        IonicModule.forRoot(MyApp, {}),
        HttpModule,
        StoreModule.provideStore({currentPurchase})
    ]
..

我得到Property currentPurchase' does not exist on type typeof app.module.导入的reducer看起来像这样:

import { ActionReducer, Action } from "@ngrx/store";
import { ActionType } from "./action-type";
import { PurchaseModel } from "../purchase/purchase.model";

export const currentPurchase: ActionReducer<PurchaseModel> = (state:PurchaseModel = new PurchaseModel(), action:Action) => {

    switch (action.type) {

        case ActionType.SET_PURCHASE:
            return (action.payload !== null) ? action.payload : new PurchaseModel();
        case ActionType.UPDATE_PURCHASE:
            return Object.assign({}, state, action.payload);
        default:
            return state;
    }
};

另外:

enter image description here

感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

对于第二个错误,您需要安装es6-shim类型,如下所述: https://github.com/angular/angular/issues/7033#issuecomment-183249303

您可以使用包json中的类型执行此操作:

npm i @types/es6-shim -S

答案 1 :(得分:1)

在reducer中使用无类型的function代替键入的const,例如像:

使用ng2-final AoT失败:

export const settings: ActionReducer<SettingsModel> = (state:SettingsModel = new SettingsModel(), action:Action) => {

    switch (action.type) {
        case ActionType.SET_SETTINGS:
            return (action.payload !== null) ? action.payload : new SettingsModel();
        case ActionType.UPDATE_SETTINGS:
            console.log(Object.assign(state, {pin: Object.assign(state.pin, action.payload.pin)}));
            return Object.assign({}, state, {pin: Object.assign(state.pin, action.payload.pin)});
        default:
            return state;
    }
};

使用ng2-final AoT:

export function settings (state:SettingsModel = new SettingsModel(), action:Action) {

    switch (action.type) {
        case ActionType.SET_SETTINGS:
            return (action.payload !== null) ? action.payload : new SettingsModel();
        case ActionType.UPDATE_SETTINGS:
            console.log(Object.assign(state, {pin: Object.assign(state.pin, action.payload.pin)}));
            return Object.assign({}, state, {pin: Object.assign(state.pin, action.payload.pin)});
        default:
            return state;
    }
};

了解更多相关信息(不会说明原因):https://github.com/ngrx/store/issues/190