Решил научиться делать Redux на Typesript. Пишу duck: файл с экшен-криэйторами и редьюсером.
Тайпскрипт ругается на переданные в
handleActions
экшен-криэйторы:
const fetchSearchSuggestionsRequest: ActionFunction1<null, Action<null>>
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
Подскажите, пожалуйста, что исправить.
Код
duck.ts
:
import { createAction, handleActions, Action } from 'redux-actions';
import { combineReducers } from 'redux';
import * as constants from './constants';
export interface ISearchSuggestion {
name: string;
}
export const fetchSearchSuggestionsRequest = createAction<null>(
constants.FETCH_SEARCH_REQUEST
);
export const fetchSearchSuggestionsSuccess = createAction<
Array<ISearchSuggestion>
>(constants.FETCH_SEARCH_SUCCESS);
export const fetchSearchSuggestionsFailure = createAction<
Array<ISearchSuggestion>
>(constants.FETCH_SEARCH_FAILURE);
const searchSuggestions = handleActions<Action<
Array<ISearchSuggestion>
> | null>(
{
[fetchSearchSuggestionsRequest]: () => null,
[fetchSearchSuggestionsSuccess]: (
_state,
action: Action<Array<ISearchSuggestion>>
) => action.payload,
[fetchSearchSuggestionsFailure]: (
_state,
action: Action<Array<ISearchSuggestion>>
) => action.payload
},
null
);
export default combineReducers({
searchSuggestions
});
Документация.
Redux + Typescript
Документация.
handleActions