store.getState()是可以获取总仓库的
先拿到函数的类型

再用ReturnType<T>
它是 TypeScript 中的一个内置条件类型,用于获取某个函数类型 T 的返回值类型

代码
    // 先拿总仓库的函数类型
    type StatefuncType = typeof store.getState;
    //再拿函数类型T的返回值类型
    type StateType = ReturnType<StatefuncType>;
    const counter = useSelector((state: StateType) => {
        return state.couterSlice;
    });可以直接一步到位
    type StateType = ReturnType<typeof store.getState>;也可以用这样
const a = store.getState();
    type a1 = typeof a;还麻烦怎么办?我想在导入的时候自带类型呢?
 用TypedUseSelectorHook 加自定义useSelector
参考:TypeScript 快速开始 | Redux 中文官网
import { configureStore } from '@reduxjs/toolkit';
import { useSelector, TypedUseSelectorHook } from 'react-redux';
import couterSlice from './modules/counter';
const store = configureStore({
    reducer: {
        couterSlice,
    },
});
export type storeType = ReturnType<typeof store.getState>;
export const useAppSelector: TypedUseSelectorHook<storeType> = useSelector;
export default store;



















