Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript set up having an issue in handleActions? #336

Open
justinlazaro-ubidy opened this issue Nov 23, 2018 · 4 comments
Open

Typescript set up having an issue in handleActions? #336

justinlazaro-ubidy opened this issue Nov 23, 2018 · 4 comments

Comments

@justinlazaro-ubidy
Copy link

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

import { handleActions } from 'redux-actions';
import {
  getHomeDataSuccess,
  getHomeDataError,
  getHomeDataLoading,
} from '../../actions/home/actions';
import Model from './model';
interface IHomeReducer {
  homes: Array<Object>;
  loading: boolean;
  state: object;
}

interface IAction {
  payload: any;
}

export default handleActions<IHomeReducer, string>(
  {
    [getHomeDataSuccess]: (state: object, action: IAction) => ({
      ...state,
      homes: action.payload,
      loading: false,
    }),
    [getHomeDataLoading]: (state, action) => ({
      ...state,
      loading: true,
    }),
    [getHomeDataError]: (state, action) => ({
      ...state,
      error: action.payload,
      loading: false,
    }),
  },
  Model,
);

@UrbanNinjaDev
Copy link

Is there typescript support for Redux 4 now? See this issue #282

@ericlau-solid
Copy link

Workaround for your issue is to force string by running toString()

    [getHomeDataSuccess.toString()]: (state: object, action: IAction) => ({
      ...state,
      homes: action.payload,
      loading: false,
    }),

@logusgraphics
Copy link

String literal also works:

[`${getHomeDataSuccess}`]: (state, action) => ...

@the-dr-lazy
Copy link

I suggest you guys take a look at thebrodmann/deox. I explained more on #282 (comment) and you can see the community feedback on the mentioned comment. For now, It's the only solution to typescript related problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants