我在 Typescript 中使用 redux-saga 和 redux-actions,如下所示:
const moviesReducer = handleActions(
{
[actions.fetchMovies]: (state) => ({
...state,
details: {...initialState.details},
}),
[actions.fetchMoviesSuccess]: (state, action) => {
return {
...state,
details: {...state.details, ...action.payload},
};
},
[actions.fetchMoviesFailed]: (state, {payload}) => ({
...state,
error: payload,
}),
},
initialState,
);
我从这里尝试了很多答案: Typescript setState with computed property names
但没有什么适合我的情况。
我得到了错误去做这个:
[actions.fetchMovies.toString()]: (state) => ({
...state,
details: {...initialState.details},
}),
但我担心这可能会在以后引起问题任何见解都会受到赞赏。
谢谢你。