Newish to typescript -我已经基于redux root-reducer的状态定义了我的全局状态。在我决定使用connected-router之前,这个方法一直运行得很好--它在root reducer中添加了一些东西--现在我不确定如何声明全局状态。
例如..。下面是我的全局状态类型:
import { StateType } from "typesafe-actions";
declare global {
export type SpaceState = StateType<
typeof import("./root_reducer").rootReducer
>;
}如果我将鼠标悬停在rootReducer上,我可以看到需要访问的属性:
const rootReducer: (history: History<unknown>) => Reducer<CombinedState<{
router: RouterState<unknown>;
ui: State;
auth: State;
}>, AnyAction>尽管在创建redux选择器来访问我的属性时,我得到了一个typescript错误。首先是我的选择器,错误出现在.ui属性下面。
export const sidebarStatus = (state: SpaceState) => state.ui.sidebarShow;下面是我得到的错误:
Property 'ui' does not exist on type 'Reducer<CombinedState<{ router: RouterState<unknown>; ui: State; auth: State; }>, AnyAction>'.我假设,由于我添加了connected-router,所以我需要以不同的方式声明我的全局状态,但我不知道如何做到这一点。感谢您的帮助或正确方向的指点。
发布于 2021-05-31 23:17:51
啊拿到了!我不得不使用ReturnType
import { StateType } from "typesafe-actions";
declare global {
export type SpaceState = StateType<
ReturnType<typeof import("./root_reducer").rootReducer>
>;
}https://stackoverflow.com/questions/67776307
复制相似问题