javascript - 使用 Redux 调度操作获取 TS 错误,“类型上不存在属性”
问题描述
我有以下 redux-thunk 动作:
import { Action } from "redux";
import { ThunkAction as ReduxThunkAction } from "redux-thunk";
import { IState } from "./store";
type TThunkAction = ReduxThunkAction<void, IState, unknown, Action<string>>;
export type TReturnValue = { someString: string };
export const someAction = (): TThunkAction => (dispatch): TReturnValue => ({
someString: "some value"
});
我像这样发送动作:
const { someString } = dispatch(someAction());
引发错误,
const { someString } = dispatch(someAction());
^^^^^^^^^^
Property 'someString' does not exist on type 'TThunkAction<void, IState, unknown, Action<string>>'
我试过像这样投射结果,
const { someString } = dispatch<TReturnValue>(someAction());
我试过重新定义TThunkAction
,但没有任何效果。
我怎样才能让 Typescript 知道调度操作的期望类型?
解决方案
推荐阅读
- flutter - 如何修复这个 Flutter xcode 构建?
- javascript - 从 DB 解析 JSON 并在前端显示
- javascript - 有条件地更改 Javascript 对象中键的顺序
- javascript - Javascript 在没有警报弹出窗口的情况下获取月/年
- bash - 如何在 Bash 中计算整数列表的总和
- nativescript - 使用谷歌提供商登录 Nativescript 应用程序的问题
- git - 如何显示实际上导致两个分支之间差异的 git 提交列表?
- javascript - 在浏览器关闭时为 React 明确清除本地存储
- python - 我的 Python 程序应该使用哪些 OpenCV FOURCC 编解码器?
- c# - 调用 PropertyChangedEventHandler 时出现 InvalidCastException