How to pass type of combineReducers. Receiving error: Property '... does not exist on type 'Reducer<CombinedState{}

How to pass type of combineReducers. Receiving error: Property '... does not exist on type 'Reducer<CombinedState{}

我正在将 typeScript 添加到我的 react/redux 项目中。我无法加载我的应用程序,因为我收到错误消息:

在 index.tsx 中,我组合了我的 reducer 并定义了类型状态:

import FormHandlerReducer from './FormHandler'
import { combineReducers} from 'redux';
import sideDrawerToggle from './sideDrawer'
import submitAlertReducer from './submitAlert'
import classesReducer from './classes'
import testReducer from './testList'
import studySessionReducer from './studySession'
import testGradeReducer from './testGradeHandler'
import homePageReducer from './homePageHandler'

const allReducers = combineReducers({studySessionReducer, FormHandlerReducer, sideDrawerToggle, submitAlertReducer, classesReducer, testReducer, testGradeReducer, homePageReducer})

export default allReducers
export type State = ReturnType<typeof allReducers>;

这是我尝试使用状态的文件

import React from 'react';
import './ShowStudySessions.css'
import { useSelector } from 'react-redux'
import State from '../../reducers'

interface ShowStudySession {
  studySessions:{
    classId: number,
    testId: number
  }
}

const ShowStudySession = ({studySessions}: ShowStudySession) => { 
  const classId = studySessions.classId
  const testId = studySessions.testId
  const studySessionList = useSelector((state: typeof State) => state.studySessionReducer[classId][testId].studySessionList)

可能打错了,你应该使用useSelector

中的type State = ReturnType<typeof allReducers>;

reducers.ts:

import { combineReducers } from 'redux';

const studySessionReducer = () => {};

const allReducers = combineReducers({
  studySessionReducer,
});

export default allReducers;
export type State = ReturnType<typeof allReducers>;

component.tsx:

import { useSelector } from 'react-redux';
import { State } from './reducers';

const ShowStudySession = ({ studySessions }) => {
  const classId = studySessions.classId;
  const testId = studySessions.testId;
  const studySessionList = useSelector((state: State) => state.studySessionReducer[classId][testId].studySessionList);

  return null;
};