javascript - 使用 typescript 将类型定义为 history.push() 已作为有效负载传递给 saga?
问题描述
我{ useHistory } from react-router-dom
在反应组件中使用过。并在按钮单击时尝试通过 action.ts 将历史实例作为有效负载传递给 saga
组件.tsx
import React from 'react';
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import {recievingHistoryAsPayload } from 'store/actions';
const Component: React.FC = () => {
const history = useHistory();
const dispatch = useDispatch();
const sendHistoryObj = () => {
dispatch(recievingHistoryAsPayload({ payload: history }));
};
return (
<Button
onClick={sendHistoryObj}
/>
);
};
export default Component;
动作.ts
export const recievingHistoryAsPayload = createAction(
Types.RECEIVING_HISTORY_AS_PAYLOAD,
(data) => data
);
saga.ts
export function* recievingHistoryAsPayloadSaga(action: any): Generator {
yield call(action?.payload?.push, '/');
}
在 saga.ts 中,对于动作有效负载 eslint 正在引发与消息的交战Argument 'action' should be typed with a non-any type.
应该为 saga.ts 中的操作定义什么类型
解决方案
推荐阅读
- jpa - 在 1 个实体中合并来自 2 条消息的数据
- solr - Solr - Geospatial search returning empty results
- mongodb - mongodb-spark-connector 的问题:java.lang.NoClassDefFoundError
- xml - 用于在具有特定标签名称的每一行的结束标签“>”之前插入字符串的 CMD 命令或脚本
- spring-boot - Getting nullpointer exception in loadUserByUsername method while validating login crendentials
- c - 为什么调用函数中的 if else 不适用于 do while 函数?
- netsuite - sca 自定义车把助手不起作用
- c# - Display Text doesn't echo back
- php - 提供的值无效(IRI 无效?) 测试 api 平台端点时出错
- c# - How to create context object accessible application-wide to store current user details in data access?