0
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.进口的减速器看起来像这样:

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

还:

在此处输入图像描述

任何帮助表示赞赏。

4

2 回答 2

1

在减速器中使用无类型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

于 2016-10-11T13:25:45.823 回答
1

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

您也可以通过以下方式对包 json 中的类型执行此操作:

npm i @types/es6-shim -S
于 2016-10-10T16:32:49.837 回答