gpt4 book ai didi

angular - on() 函数创建 Reducer 时出错

转载 作者:行者123 更新时间:2023-12-02 18:54:25 24 4
gpt4 key购买 nike

刚刚接近 ngrx 的使用,我有一个我无法解决的未处理错误,尝试搜索但没有,这是错误。

error

它告诉我必须输入 4 个参数,但无论我在哪里搜索正确的语法和另一种选择,有人知道问题出在哪里吗?谢谢

这里是reducer的页面,我把action的页面也贴出来,有消息告诉我

import { createReducer, on, Action } from '@ngrx/store';
import * as ProvaActions from './prova.actions';
import { ProvaState } from './prova.model';


export const initialState: ProvaState = {
user: {},
error: false
}

const provaReducer = createReducer(
initialState,
on(ProvaActions.editProvaSuccess, (state, action ) => ({user: action.user , error: false })),
on(ProvaActions.editProvaFailed, (state, action ) => ({ user: {}, error: true }))
);

export function reducer(state: ProvaState | undefined, action: Action) {
return provaReducer(state, action);
}

import { createAction, props } from '@ngrx/store';


export const editProva = createAction(
'[Prova] Edit',
props<{user: any}>() //payload, parametri che passo
)

export const editProvaSuccess = createAction(
'[Prova] Edit Success',
props<{user: any}>()
)

export const editProvaFailed = createAction(
'[Prova] Edit Failure')

export interface ProvaState {
user: any,
error: boolean;
}

最佳答案

我遇到了同样的问题。我就是这样解决的。

  • 确保您已安装 Typescript 4.1.5。

  • 将您的 VSCode Workspace Typescript 版本(在右侧底部工具栏中)更改为 4.1.5。

关于angular - on() 函数创建 Reducer 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66353169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com