确保Account Reducer中的initialState和Interface的属性完全匹配。例如:
interface AccountState { name: string; email: string; isLoading: boolean; }
const initialState: AccountState = { name: "", email: "", isLoading: false }
function accountReducer(state = initialState, action: any) { switch (action.type) { case "SET_ACCOUNT": { return { ...state, name: action.payload.name, email: action.payload.email, isLoading: false } } case "SET_LOADING": { return { ...state, isLoading: true } } default: { return state } } }
在上面的示例中,AccountState和initialState定义了Account Reducer的初始状态和类型。在SET_ACCOUNT action中,payload的属性必须与接口的属性名称完全匹配,以便正确分配值。