我有一个使用TS定义的功能组件,我在Props中传入对象以使该组件可以访问某些actionCreators。没有要传递的实际Props值。但是,我正在使用prop机制传递一个类型来访问actionCreator方法。
import * as React from 'react';
import { connect, useSelector, useDispatch } from 'react-redux';
import { ApplicationState } from "../store";
import * as VerifyCheckStore from "../store/VerifyCheck";
type VerifyCheckProps = typeof VerifyCheckStore.actionCreators;
const VerifyCheckVerificationSuccess: React.FunctionComponent<VerifyCheckProps> = (props) =>
{
const selectVerifyCheckState = (state: ApplicationState) => state.verifyCheck;
const verifyCheckState: any = useSelector(selectVerifyCheckState);
const dispatch = useDispatch();
const submitData = (processState: string) => {
VerifyCheckStore.actionCreators.setProcessState(processState);
}
return <div>
<div>Check has been verified as a valid AutoCheck</div>
<div>Do you wish to adopt this Autocheck for the purpose of using the check to pay for a customer's vehicle?</div>
<button className="btn btn-primary" name="btnAdopt" onClick={() => { submitData("adoptStart") }} >Adopt</button>
<button className="btn btn-primary" name="btnAdopt" onClick={() => { submitData("start"); }} >Cancel</button>
</div>;
}
VerifyCheckVerificationSuccess.defaultProps = {}
export default connect()(VerifyCheckVerificationSuccess);
当我使用FC时,出现以下TS错误。
错误TS2739(TS)类型'{}'缺少类型'Pick <{setProcessState:(processState:string)=> AppThunkAction;中的以下属性; postdata:(checkNumber:字符串,VerificationCode:字符串)=> AppThunkAction; requestVerifyCheck:()=> AppThunkAction <...>; },“ setProcessState” | ... 1更多... | “ requestVerifyCheck”>':setProcessState,postdata,requestVerifyCheck
使用FC时如何在props机制中传递对象而不必定义值?
如果这不是访问actionCreator方法的正确方法,请告诉我。我是React的新手,只是学习而已。
答案 0 :(得分:0)
通过将“ as any”添加到导出默认连接中,我能够使错误消失。我知道这是一种黑客行为,并未按计划真正使用TS,但我必须继续前进。
export default connect()(VerifyCheckVerificationSuccess as any);