A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts

2.1k Views Asked by At

I am using redux-saga and redux-actions with Typescript, like this:

 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,
    );

I have tried many answers from here: Typescript setState with computed property names

but nothing fits my case.

I got the error to go doing this:

[actions.fetchMovies.toString()]: (state) => ({
  ...state,
  details: {...initialState.details},
}),

But I am afraid that may cause issues later on Any insight would be appreciated.

Thank you.

0

There are 0 best solutions below