Я получаю эту ошибку TypeScript. Свойство 'hasError' не существует для типа '(состояние: ErrorType | undefined, действие: ErrorActionType) => ErrorType'. который, я думаю, он жалуется на установку initialState для редуктора.
import { ErrorType, ErrorActionType } from '../actions';
import { ActionTypes } from '../types';
export const errorReducer = (
state: ErrorType = { hasError: false, errorMessage: '' },
action: ErrorActionType
) => {
switch (action.type) {
case ActionTypes.setError:
return action.payload;
default:
return state;
}
};
и вот мое действие
import { Dispatch } from 'redux';
import { ActionTypes } from '../types';
export interface ErrorType {
hasError: boolean;
errorMessage: string;
}
export interface ErrorActionType {
type: ActionTypes.setError;
payload: ErrorType;
}
export const setError = (hasError: boolean, errorMessage: string) => {
return (dispatch: Dispatch) => {
dispatch<ErrorActionType>({
type: ActionTypes.setError,
payload: { hasError, errorMessage },
});
};
};
, а также мой reducer.index
import { combineReducers } from 'redux';
import { errorReducer } from './error';
import { loadingReducer } from './loading';
import { newsReducer } from './news';
import { schoolsReducer } from './schools';
import { StoreStateType } from '../types';
export const reducers = combineReducers<StoreStateType>({
isLoading: loadingReducer,
hasError: errorReducer.hasError,
errorMessage: errorReducer.errorMessage,
news: newsReducer,
schools: schoolsReducer,
});
вот тип состояния приложения
export interface StoreStateType {
isLoading: boolean;
hasError: boolean;
errorMessage: string;
news: NewsType[];
schools: SchoolType[];
}